Detect when UIGestureRecognizer is up, down, left and right Cocos2d(检测UIGestureRecognizer何时上下左右Cocos2d)
问题描述
我有一个 CCSprite,我想用手势四处移动.问题是我对 Cocos2D 完全陌生.我希望我的精灵在手势向上时执行一个动作,在手势向下时执行另一个动作,在手势正确时执行另一个动作,向左执行相同操作.有人可以指出我正确的方向吗?
I have a CCSprite that I want to move around using gestures. Problem is I'm completely new to Cocos2D. I want my sprite to perform one action when the gesture is up, another one when gesture is down, another action when gesture is right and same thing for left. Can someone point me in the right direction?
谢谢!
推荐答案
显然每个 UISwipeGestureRecognizer 只能检测到给定方向的滑动.即使方向标志可以被或在一起,UISwipeGestureRecognizer 也会忽略其他标志.
Apparently each UISwipeGestureRecognizer can only detect the swipe in the given direction. Even though the direction flags could be OR'ed together the UISwipeGestureRecognizer ignores the additional flags.
解决方案是为您希望识别滑动手势的每个方向添加一个 UISwipeGestureRecognizer,并将每个识别器的方向相应地设置为上、下、左和右.如果你想测试任何方向的滑动,你必须添加四个 UISwipeGestureRecognizers.
The solution is to add one UISwipeGestureRecognizer for each direction you want the swipe gesture to be recognized, and set each recognizer's direction accordingly to either up, down, left and right. If you want to test for a swipe in any direction you'll have to add four UISwipeGestureRecognizers.
这有点奇怪,但这是对我有用的唯一方法.
It's kind of odd but that's the only way it worked for me.
这篇关于检测UIGestureRecognizer何时上下左右Cocos2d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检测UIGestureRecognizer何时上下左右Cocos2d
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01