我在检测摇动的时候有问题。这是Sprit Kit中的一个淫秽场景,我定义了这样的运动检测器:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"test?");
}我的错误在哪里?我必须像用UIGestureRecognizer那样实现它吗?
提前感谢朱利安(对我英语不好表示歉意)
发布于 2014-12-29 06:02:10
显然,您无法从SKScene子类(如GameScene )中检测到抖动事件。但是,您可以从视图控制器(如GameViewController )中检测到它们。当触发抖动事件时,可以从视图控制器调用GameScene中的抖动处理程序。
在GameViewController.m中,添加此选项以检测抖动事件
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
SKView *skView = (SKView *)self.view;
GameScene *scene = (GameScene *)skView.scene;
// Call a function in the GameScene
[scene shake];
}
}将其添加到GameScene.h中的@接口
- (void) shake;将此添加到GameScene.m中
- (void) shake {
NSLog(@"shake");
}https://stackoverflow.com/questions/27679491
复制相似问题