iosswiftsprite-kitskaction

SKActions Doesn't works sometimes, but if minimise the game and reopen it, It Works. How that could happen?


I'm having problem with 2 actions both of the actions are move to actions, that moves the pieces to empty node's position(Empty sknodes are added from sks file for). The problem only happens some times not always, in first one when player reaches loc:25 means wins it moves to empty node's position but it some times doesn't moves to there but the game goes on and if I minimise the game and open it they are already there where they should have moved previously.

Second problem this one is more important because with this skaction player moves to next Position. But very few times it doesn't works everything works fine but when it comes to execute that skaction it Stops totally, only touches works. but if I just minimise the game and open it, it moves to position and then game works fine. No issue then, How can this Happen?

I run the second skaction with sequence with 2 other actions and first one with skspritenode.run() action. and I don't have iOS device so I'm testing it on simulator.

Here are the both of SKActions that I use just the same thing nothing new :

for node in children {

        if (node.name == String(nextSpace)) {

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

        let wait:SKAction = SKAction.wait(forDuration: 0.1)
        let runAction:SKAction = SKAction.run({

            if (self.movesRemaining == 1) {

                self.KillHim(self.whosTurn, nextspace: nextSpace)

            }

            self.movesRemaining = self.movesRemaining - 1
            self.setThePlayerSpace(space: nextSpace, player:self.whosTurn)

            self.movePiece()

            })
            if whosTurn == .Player1 {

                touchedNode.run(SKAction.sequence([moveAction, wait, runAction]))

            } else {

                playerPiece.run(SKAction.sequence([moveAction, wait, runAction]))

            }
        }
    }

code for moving when player won :

if (currentSpacePlayer1Piece1 == 25) {

               let loc:SKNode = childNode(withName: "c1")!
               Player1Piece1.run(SKAction.move(to: loc.position, duration: 0.2))
               currentSpacePlayer1Piece1 = 26
               OneMoreMove += 1
 } else if (currentSpacePlayer1Piece2 == 25) {

               let loc:SKNode = childNode(withName: "c2")!
                Player1Piece2.run(SKAction.move(to: loc.position, duration: 0.2))
                currentSpacePlayer1Piece2 = 26
                OneMoreMove += 1
 }

is it could be happening because of using it in simulator?


Solution

  • As knightOfDragon said the node was being paused with some logic some times after removing, it works perfectly. If you have same issue search isPaused if you are using it somewhere not intended.