ios – 如何在spriteKit和swift中区分手势和触摸?

ios – 如何在spriteKit和swift中区分手势和触摸?,第1张

概述我有两个功能,一个在我触摸场景时被激活而另一个在我做出手势时被激活,但是当我做出一个手势时,场景检测到一个触摸并执行这两个功能 class GameScene: SKScene, SKPhysicsContactDelegate {override func didMoveToView(view: SKView) { /* Setup your scene here */ / 我有两个功能,一个在我触摸场景时被激活而另一个在我做出手势时被激活,但是当我做出一个手势时,场景检测到一个触摸并执行这两个功能

class GameScene: SKScene,SKPhysicsContactDelegate {overrIDe func dIDMovetoVIEw(vIEw: SKVIEw) {    /* Setup your scene here */    // physics & collisions    physicsWorld.gravity = CGVectorMake(0.0,0.0)    physicsWorld.contactDelegate = self    // Swipe down    let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self,action: Selector("swipedDown:"))    swipeDown.direction = .Down    vIEw.addGestureRecognizer(swipeDown)}//MARK: Swipesfunc swipedDown(sender:UISwipeGestureRecognizer){    //first function    swipeDown()}//MARK: touchesoverrIDe func touchesBegan(touches: Set<UItouch>,withEvent event: UIEvent?) {    /* Called when a touch begins */    for touch in touches {        let location = touch.locationInNode(self)        // second function        attack()    }}}
解决方法 而不是touchesBegan,尝试使用轻击手势(UITapGestureRecognizer)进行攻击 *** 作.

这不是必需的,但如果在滑动和点击之间仍然存在冲突,请使用requireGestureRecognizerToFail使轻击手势取决于滑动失败,以确保在滑动过程中未检测到轻击.

总结

以上是内存溢出为你收集整理的ios – 如何在spriteKit和swift中区分手势和触摸?全部内容,希望文章能够帮你解决ios – 如何在spriteKit和swift中区分手势和触摸?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1048193.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存