取消点击手势重新配置器

取消点击手势重新配置器

本文介绍了取消点击手势重新配置器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考我的最后一个问题:

Referring to my last question:

Sprite 暂停后移动两个位置然后未暂停

我有一个点击手势,它可以将我游戏中的精灵向前移动 1 个空格,当我按下暂停按钮时,它会继续注册点击手势,然后当我恢复游戏玩法时,它会移动两个空格.

Hi, I have a tap gesture which moves a sprite in my game forward 1 space and when I press the pause button it continues to register the tap gesture and then when I resume the gameplay It moves two spaces.

所以我设法定义了一个 bool 变量来检测(使用 if 语句)我是否暂停了点击手势

so I managed to define a bool variable that detects (using if statements) if I have paused the tap gesture

var tapIsPaused: Bool = false



func tapUp(){

    if(tapIsPaused == true) {

        //do nothing


    } else if (tapIsPaused == false) {

        let amountToMove:CGFloat = levelUnitHeight

        let move:SKAction = SKAction.moveByX(0, y: amountToMove, duration: 0.1)


        menubutton.hidden = true
        settingsButton.hidden = true
        highscoreLabel.hidden = true
        pauseButton.hidden = false

        thePlayer.runAction(move)

        clearNodes()

    }

}

但我现在遇到的问题是,当我按下恢复按钮恢复游戏时,它仍然会移动精灵,但这次它只向上移动一个空间,这是因为当我按下恢复按钮时,它会转动水龙头然后注册恢复按钮的点击以将播放器向上移动.

But the problem I have now is that when I press the resume button to resume the gameplay it still moves the sprite, but this time it's only moving one space up, which is because when I press the resume button it turns the tap on which then registers the tap of the resume button to move the player up.

我该如何解决这个问题?

How can I fix this?

这是我的暂停按钮:

 else if (node == pauseButton) {

        tapIsPaused = true
        pauseButton.removeFromParent()
        addChild(resumeButton)
        addChild(restartButton)
        self.runAction (SKAction.runBlock(self.pauseGame))

    }

这是我的简历按钮:

 else if (node == resumeButton) {


        resumeButton.removeFromParent()
        restartButton.removeFromParent()
        addChild(pauseButton)
        self.runAction (SKAction.runBlock(self.resumeGame))
        tapIsPaused = false

    }

这是我的点击手势处理程序代码:

Here is my tap gesture handler code:

 let TapUpRec = UITapGestureRecognizer()




 TapUpRec.addTarget(self, action: "tapUp")
    self.view!.addGestureRecognizer(TapUpRec)

推荐答案

您可以使用以下方法移除暂停点击手势:

You can remove Gesture on Pause click using following:

self.view.removeGestureRecognizer(YOUR_GESTURE_RECOGNISER)

并在恢复游戏时再次添加

and add it again if resume game

这篇关于取消点击手势重新配置器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:21