gpt4 book ai didi

iphone - 如何在 Cocos2d CCLayer 中添加摇动手势?

转载 作者:行者123 更新时间:2023-12-03 19:01:05 28 4
gpt4 key购买 nike

我尝试过使用shake Gesture Recognition wrapper来检测摇动手势。我还尝试实现 Geeky Lemon 中建议的代码。但我无法处理摇动手势。有什么办法可以识别摇动手势吗?

谢谢!

编辑1:

该代码是在摇动手势识别包装演示的帮助下完成的。

在init方法中

ShakeDispatcher * dispatcher = [ShakeDispatcher sharedInstance];
[dispatcher addShakeListener:self];
[[[CCDirector sharedDirector]view] addGestureRecognizer:dispatcher];

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if ( event.subtype == UIEventSubtypeMotionShake ){
NSLog(@"Shake detected");
}
}

最佳答案

以正常方式创建手势识别器,然后像这样添加

[[[CCDirector sharedDirector] view] addGestureRecognizer:shakeGesture];

关于iphone - 如何在 Cocos2d CCLayer 中添加摇动手势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12092216/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com