我有两种功能,一种是在我触摸场景时激活的,另一种是在我做出手势时激活的,但是当我做出手势时,场景会检测到触摸并执行这两种功能

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: Swipes
func swipedDown(sender:UISwipeGestureRecognizer){
    //first function
    swipeDown()
}

//MARK: Touches
override 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中区分手势和触摸?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34259649/

10-11 22:46
查看更多