检测UIGestureRecognizer何时向上,向下,向左和向右Cocos2d [英] Detect when UIGestureRecognizer is up, down, left and right Cocos2d
问题描述
我有一个CCSprite,我想使用手势移动。问题是我是全新的Cocos2D。我想让我的精灵执行一个动作,当手势向上时,另一个当手势是下来,另一个动作时手势是正确的和左边相同的事情。有人能指点我的方向吗?
谢谢!
显然,每个UISwipeGestureRecognizer只能检测指定方向的滑动。即使方向标志可以在一起ORIS,UISwipeGestureRecognizer忽略额外的标志。
解决方案是添加一个UISwipeGestureRecognizer您要滑动手势的每个方向识别,并且将每个识别器的方向相应地设置为上,下,左和右。如果你想测试任何方向的滑动,你必须添加四个UISwipeGestureRecognizer。
这是奇怪的,但这是唯一的方式为我工作。 / p>
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?
Thanks!
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.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!