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
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01