检测UIGestureRecognizer何时上下左右Cocos2d

Detect when UIGestureRecognizer is up, down, left and right Cocos2d(检测UIGestureRecognizer何时上下左右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

基础教程推荐