Highway Rider-Extreme rush

In the game, you are a motorcycle enthusiast, and now you are participating in a high-speed cycling competition. Unlike the usual ones, the track is held on the highway. If you avoid the passing vehicles as soon as possible, it is a big difficulty. Let us try it together!

Realization of gravity sensing

UIAccelerometer accelerometer is used to detect iphone mobile phone in the x.y.z axis acceleration on the three axes. To get this type of call:

UIAccelerometer * accelerometer = [UIAccelerometer sharedAccelerometer];

At the same time, you need to set its delegate.

UIAccelerometer * accelerometer = [UIAccelerometer sharedAccelerometer];

accelerometer.delegate = self;

accelerometer.updateInterval = 1.0 / 60.0;

The delegate method: - (void) accelerometer: (UIAccelerometer *) accelerometer didAccelerate: (UIAcceleration *) The UIAcceleration in acceleration is the acceleration class. Contains really data from the accelerometer UIAccelerometer. It has 3 attributes x, y, z. iphone accelerometer support up to 100 times per second frequency polling. This time is 60 times.

1) The application can detect the shaking through the accelerometer, for example, the user can erase the drawing by shaking the iphone.

Users can also shake iphone several times in a row, the implementation of some special code:

- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration

{

static NSInteger shakeCount = 0;

static NSDate *shakeStart;

NSDate *now = [[NSDate alloc] init];

NSDate *checkDate = [[NSDate alloc] initWithTimeInterval:1.5f sinceDate:shakeStart];

if ([now compare:checkDate] == NSOrderedDescending || shakeStart == nil)

{

shakeCount = 0;

[shakeStart release];

shakeStart = [[NSDate alloc] init];

}

[now release];

[checkDate release];

if (fabsf(acceleration.x) > 2.0 || fabsf(acceleration.y) > 2.0 || fabsf(acceleration.z) > 2.0)

{

shakeCount++;

if (shakeCount > 4)

{

// -- DO Something

shakeCount = 0;

[shakeStart release];

shakeStart = [[NSDate alloc] init];

}

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容