Accelerometer in the iPhone Simulator
It can be a frustrating and time consuming task to work with the accelerometer feature in iPhone development. The iPhone Simulator does not come with any built-in capabilities to receive accelerometer events from factory.
Some developers accomplished a way to simulate it in the Simulator. One technique involves using a third party library that generate events and send them to your program. Another technique is kind of esoteric, as it reads your internal MacBook accelerometer and handle them as they would come from an iPhone. I just can’t imagine myself turning my MacBook upside-down just to test our game
I got a simple solution to simulate it. First I call the accelerometer from my update function (notice that I’m using a preprocessor macro), using nil as parameters:
#ifdef ACCELEROMETER_SIM [self accelerometer:nil didAccelerate:nil]; #endif
Then, on the accelerometer function, I test the program directly inputting the vectors that I need to test. In this case I want to test the Y axis:
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
{
// Use a basic low-pass filter to keep only the gravity component of each axis.
mAccelX = (acceleration.x * FILTER) + (mAccelX * (1.0 - FILTER));
mAccelZ = (acceleration.z * FILTER) + (mAccelZ * (1.0 - FILTER));
#ifdef ACCELEROMETER_SIM
mAccelY = (-1.0f * FILTER) + (mAccelY * (1.0 - FILTER));
#else
mAccelY = (acceleration.y * FILTER) + (mAccelY * (1.0 - FILTER));
#endif
}
It’s super simple, and you can have your tests right from your iPhone Simulator. No more uploading to device just to test
No comments
No comments at this moment.
RSS feed for comments on this post.
Sorry, the comment form is closed at this time.
See also
- Cashtown ·· All the colors and art of a time
- Cashtown ·· Dealing with NSCalendar and dates
- Cashtown ·· Cashtown’s Image
- How we work ·· Our games are exclusive
- Cashtown ·· A bit of its way of thinking



