SpriteKit - 快速触摸会导致错误行为

SpriteKit - Quick touches cause wrong behaviour

我目前正在开发一款横版卷轴游戏,其中跳跃高度取决于玩家按下屏幕右半边的时间。 一切正常,除非用户快速触摸屏幕。这导致跳跃尽可能大。

我是不是做错了什么,或者这只是 SpriteKit 工作方式的问题? 我该如何解决这个问题?

编辑:以下是我游戏中处理触摸的所有方法:

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
    for touch in touches
    {
        swiped = false

        let location = touch.location(in: cameraNode)

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.065)
        {
            if self.swiped == false
            {
                if location.x < 0
                {
                    self.changeColor()
                }
                else
                {
                    self.jump()
                }
            }
        }
    }

}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)
{
    for touch in touches {
        let location = touch.location(in: cameraNode)

            if location.x > 0
            {
                // Right
                thePlayer.endJump()
            }
    }
}

然后还有一个手势识别器处理左右滑动,具有以下处理程序:

    @objc func swipedRight()
{
        if walkstate != .walkingRight
        {
            walkstate = .walkingRight
        }
        else
        {
            boost(direction: 0)
        }

        swiped = true
}

@objc func swipedLeft()
{

        if walkstate != .walkingLeft
        {
            walkstate = .walkingLeft
        }
        else
        {
            boost(direction: 1)
        }

        swiped = true
}

希望这足以描述问题。上面的代码是我为处理触摸所做的一切。

嗯,问题是,我正在使用 DispatchQueue 命令在短暂的延迟后调用跳转方法,以防用户滑动而不是点击。结果,touchesEnded 方法在跳转开始之前就被调用,因此无法再停止。

为了解决这个问题,我添加了一个布尔变量,只要玩家触摸屏幕就设置为 true,只要用户手指离开屏幕就设置为 false。为了跳跃,必须将此变量设置为 true,因此角色在快速触摸后将不再跳跃。