2014-12-04 2 views
0

설정 한 SKAction 시퀀스에 문제가 있습니다.스프라이트 키트 관련 문제 Swift의 SKAction

이 시퀀스의 목표는 9 개의 스프라이트 노드 어레이를 취하여 한 번에 하나씩 표시하는 것입니다. 이 시퀀스는 어떤 버튼이 눌러 졌는지에 따라 현재 노드의 오른쪽 또는 왼쪽에있는 노드를 표시합니다 (오른쪽 단추 또는 왼쪽 단추).

여기서 흥미로운 점이 있습니다. 그것은 지금처럼 작동하는 것처럼 보입니다. 그러나 버튼 왼쪽이나 오른쪽 버튼을 여러 번 빨리 누르면 유지할 수없는 것처럼 보이고 프로세스가 실패합니다. 오류가 발생하지 않습니다. 스프라이트 노드가 표시되지 않거나 제대로 표시되지 않습니다.

아래 코드를 첨부했습니다. 내가 천천히 순환 할 때 작동하기 때문에 타이밍 문제라고 생각하고 완성 블록을 추가해야 할 수도 있습니다. 나는 이것을 시도했지만 성공하지 못했습니다.

제 질문은 여기에 잘못 나온 부분이 있는지, 완성 블록으로 문제를 해결할 수 있다고 생각하십니까?

func pressedButtonRight(){ 
    if currentDisplayedWorld < 8 { 
     var currentWorld:SKSpriteNode = worldArray[currentDisplayedWorld] as SKSpriteNode 
     var nextWorld:SKSpriteNode = worldArray[currentDisplayedWorld + 1] as SKSpriteNode 
     nextWorld.position = CGPointMake(self.frame.size.width, 50) 
     self.addChild(nextWorld) 

     let move = SKAction.moveByX(-self.frame.size.width, y: 0, 
      duration: 1.0, delay: 0, 
      usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5) 

     //currentWorld.runAction(move) 
     nextWorld.runAction(move) 
     currentWorld.removeFromParent() 

     currentDisplayedWorld++ 
    }else if currentDisplayedWorld == 8 { 

    } 
} 

func pressedButtonLeft(){ 
    if currentDisplayedWorld > 0 { 
     var currentWorld:SKSpriteNode = worldArray[currentDisplayedWorld] as SKSpriteNode 
     var previousWorld:SKSpriteNode = worldArray[currentDisplayedWorld - 1] as SKSpriteNode 
     previousWorld.position = CGPointMake(-self.frame.size.width, 50) 

     self.addChild(previousWorld) 

     let moveBack = SKAction.moveByX(self.frame.size.width, y: 0, 
      duration: 1.0, delay: 0, 
      usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5) 

     //currentWorld.runAction(moveBack) 
     previousWorld.runAction(moveBack) 
     currentWorld.removeFromParent() 

     currentDisplayedWorld-- 
    }else if currentDisplayedWorld == 0 { 

    } 
} 
+0

에는 move라는 클래스 속성 부울이 있습니다. 이동이 거짓 인 경우에만 노드를 이동하십시오. 노드 집합을 true로 이동하기 전에 이동하십시오. 완료 핸들러로 노드에서 이동 조치를 실행하면 false로 다시 이동합니다. – Okapi

+0

코드는 실제로 실행중인 작업을 실제로 중지하지 않습니다. 버튼을 빠르게 누르면 여러 가지 동작을 동시에 실행할 수 있습니다. 그 동작은 정의되지 않았습니다. "키를 사용하여"작업을 실행하면 작업을 실행하면 이미 실행중인 다른 키와 동일한 작업이 자동으로 중지됩니다. – LearnCocos2D

+0

좋습니다. 나는 이것을 오늘 시험해보고 효과가 있는지 알려 줄 것이다. 감사. –

답변

0

완벽하게 해결했습니다. 나는 모든 사람이 볼 수 있도록 아래에 최종 코드를 게시했다. 도움에 다시 한번 감사드립니다.

func pressedButtonRight(){ 
    if currentDisplayedWorld < 8 { 

     if self.moving == false { 
      self.moving = true 

      var currentWorld:SKSpriteNode = self.worldArray[currentDisplayedWorld] as SKSpriteNode 
      var nextWorld:SKSpriteNode = self.worldArray[currentDisplayedWorld + 1] as SKSpriteNode 
      nextWorld.position = CGPointMake(self.frame.size.width, 50) 

      self.addChild(nextWorld) 

      let move = SKAction.moveByX(-self.frame.size.width, y: 0, duration: 1.0, delay: 0,usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5) 

      //currentWorld.runAction(move) 
      nextWorld.runAction(move, completion: { 
       self.moving = false 
      }) 
      currentWorld.removeFromParent() 
      currentDisplayedWorld++ 
     } 

    }else if currentDisplayedWorld == 8 { 

    } 
} 

func pressedButtonLeft(){ 
    if currentDisplayedWorld > 0 { 

     if self.moving == false { 
      self.moving = true 

      var currentWorld:SKSpriteNode = self.worldArray[currentDisplayedWorld] as SKSpriteNode 
      var previousWorld:SKSpriteNode = self.worldArray[currentDisplayedWorld - 1] as SKSpriteNode 
      previousWorld.position = CGPointMake(-self.frame.size.width, 50) 

      self.addChild(previousWorld) 

      let moveBack = SKAction.moveByX(self.frame.size.width, y: 0, duration: 1.0, delay: 0, 
       usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5) 

      //currentWorld.runAction(moveBack) 
      previousWorld.runAction(moveBack, completion: { 
        self.moving = false 
      }) 
      currentWorld.removeFromParent() 
      currentDisplayedWorld-- 
     } 

    }else if currentDisplayedWorld == 0 { 

    } 
} 
관련 문제