I am developing an application in which iPhone will play different sounds when moved (sword). I want to know when iPhone has moved left, right, up or down (sword movement). How can I implement this? I was testing the accelerometer and wrote this code, but it returns the same values if moved left or right. How can I know in which direction is the iPhone moved?
Code:
- (void)accelerometer:(UIAccelerometer *)accelerometer
didAccelerate:(UIAcceleration *)acceleration
{
double const kThreshold = 1.0;
if (fabsf(acceleration.x) > kThreshold) {
NSLog(@"X+");
}
}