If you’re struggling with odd behavior from your device’s accelerometer ‘every now and again’ then you’re not alone.
This post comments on the problem and some work arounds, and this is what I’ve found:
Problem:
A few devs out there have noticed the following symptoms
- The accelerometer will not respond via the delegate at all in your app about 5% of the time when running your app
- When combined with OpenGLES surfaces, the first drawn frame will be drawn between every new frame drawn to the surface. This results in a flickering effect where a ‘ghost’ of your initial drawing is interlaced with your normal frames.
Although some have reported these two problems being one and the same, I found them to be quite separate. I think many people are using the accelerometers+OpenGLES for games, and because the problems happen infrequently they seem related. I could be wrong of course. For the same reasons I could just be imagining that they aren’t related.
Work-arounds (not really solutions):
Accelerometer not working
For the accelerometer, many have found (and I have too) that the problem seems to go away if you set the update frequency and delegate much later on in your app.
[[UIAccelerometer sharedAccelerometer] setUpdateInterval: (1.0 / kAccelerometerFrequency)]; [[UIAccelerometer sharedAccelerometer] setDelegate:self];
Typically, you’ll call the above lines in
- (void)applicationDidFinishLaunching:(UIApplication *)application
but that’s what causes the problems. Anyones best guess is that it just takes too long for the accelerometer to get ready some times and it just ignores your set delegate request.
Flashing graphics
I can’t confirm that this fix works, but some have reported that using kEAGLColorFormatRGBA8 instead of kEAGLColorFormatRGB565 on your OpenGLES surface will stop it happening. I’ll give it a try and post my results here. If anyone can confirm or deny this fix, we’d love to hear from you.
Hello,
http://www.iphonedevresource.com to GoogleReader!
Thanks
AnnaHopn