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
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
