Как двигаться и прыгать с SKSpriteNode одновременно - PullRequest
0 голосов
/ 26 июня 2018

В настоящее время у меня есть прыжки и перемещения, работающие с двумя кнопками Это узлы SKSpriteNode, и я вызывал каждое действие при касании. Проблема, с которой я сталкиваюсь, заключается в том, что когда я нажимаю одну кнопку, действие срабатывает, а когда я нажимаю другую кнопку, другое действие останавливается, потому что кнопка больше не касается. Я пытаюсь позволить пользователю двигаться и прыгать одновременно. Например, удерживайте левую кнопку и нажмите кнопку перехода.

 // MARK: Touches
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    for touch: AnyObject in touches {
        let pointTouched = touch.location(in: cameraNode)
        if leftArrow.contains(pointTouched)
        {
            leftArrow.alpha = 0.5
            moveWizard(moveBy: -300, forTheKey: "moveX")
            wizardRunAnimation()
            wizardCharacter.xScale = -1
        }
        if rightArrow.contains(pointTouched)
        {
            rightArrow.alpha = 0.5
            moveWizard(moveBy: 430, forTheKey: "moveX")
            wizardRunAnimation()
            wizardCharacter.xScale = 1
        }
        if attackButton.contains(pointTouched)
        {
            attackButton.alpha = 0.5
            wizardAttackAnimation()
        }
        if upArrow.contains(pointTouched)
        {
            upArrow.alpha = 0.5
            jumpWizard(forTheKey: "jumped")
            jumpWizardAnimation(fortheKey: "jumpedAnimation")
        }
    }
}
func alpha() {
    leftArrow.alpha = 1
    rightArrow.alpha = 1
    attackButton.alpha = 1
    upArrow.alpha = 1
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    for touch: AnyObject in touches {
        let pointTouched = touch.location(in: cameraNode)
        if leftArrow.contains(pointTouched)
        {
            wizardCharacter.removeAction(forKey: "moveX")
        if rightArrow.contains(pointTouched)
        {
            wizardCharacter.removeAction(forKey: "moveX")
        }
        if attackButton.contains(pointTouched)
        {
            wizardCharacter.removeAction(forKey: "wizardRun")
        }
        if upArrow.contains(pointTouched)
        {
           wizardCharacter.removeAction(forKey: "jumped")
        }
    }                  
...