SkSpriteNode.Run Action don't Works some times

北战南征 提交于 2019-12-12 10:21:42

问题


this is my first SpriteKit game and I didn't had any problems with run action before so I tried but can't figure anything out, only thing I figure out is all code is fine but just run action don't execute some times and didn't seen any king of behaviour in that pattern.

I I'm making 4 player board game and all 4 players have 4 pieces. the problem is with returning to home when ever any player piece kills other player's piece that piece comes back to home before it was working fine but I added new feature of when player kills other player or wins it gets 1 more turn to play. after adding that now I'm having this problem sometimes, that the piece gets killed it's current location var's value changes to whatever is it's home number but the action to move it to there doesn't works some times. after that because current location var changed it's location to it's home number whenever next time ai function will decide to move that piece or if it's human player and we decide to move that piece that piece's next location now set to 1+ home location so then where ever it was froze it comes to that location (1+ home)

here is the code for that killing function actually it is for 4 player's 4 pieces but it is very long that's why I'm posting only of 1 player's.

func KillHim(player:Player, nextspace:Int) {

if (player == .Player2) {

            if (nextspace == currentSpacePlayer2Piece1) {

                for node in children {

                    print("Inside the node in children player1 csp2p1 :")

                    if node.name == ("5") {

                        print("Inside the if NODE name is == 5")

                        let moveAction:SKAction = SKAction.move(to: node.position, duration: 0.5)

                 Player2Piece1.run(moveAction) {
                            print("It Happened")
                        }

                            self.currentSpacePlayer2Piece1 = 5

                        player1Moves += 1
                    }
                }
            }
         }
      }

UPDATE :

Now it Works after removing the 1 more turn parameters.

in the did move to view when it again gives the turn to the same player then it didn't works.

Here is the CODE :

it's after all the counting and move action finished so after that in else condition it changes the player Turn.

} else {

            if (self.whosTurn == .Player1) {

              //  if (player1Moves == 0) {

                    self.whosTurn = .Player2

                    flashPlayer(player: whosTurn)

                    flashTurn(player: whosTurn)

                    print("Who's Turn is Player2 NOW")

                    rollDice(player: whosTurn)

               // } else {
                   // self.whosTurn = .Player1

                 //   flashPlayer(player: whosTurn)

                  //  flashTurn(player: whosTurn)

                  //  print("InSide 1MORE MOVE ::  : : ; ; :")
                   // player1Moves -= 1

                  //  rollDice(player: whosTurn)
              //  }

            } else if (self.whosTurn == .Player2) {

              //  if (player2Moves == 0) {

                self.whosTurn = .Player3

                flashPlayer(player: whosTurn)

                flashTurn(player: whosTurn)
                print("Who's Turn is Player3 NOW")

                rollDice(player: whosTurn)

              //  } else {
                   // self.whosTurn = .Player2

               //     flashPlayer(player: whosTurn)

               //     flashTurn(player: whosTurn)
                //    print("InSide 1MORE MOVE ::  : : ; ; :")
                //    player2Moves -= 1

                //    rollDice(player: whosTurn)
               // }

            }
    }

Can anyone please tell me why do this Happens?

来源:https://stackoverflow.com/questions/52089909/skspritenode-run-action-dont-works-some-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!