SKAction no longer works after removing and re-adding SKSpriteNodes

So I have a simple card game which has a deal function. When called it takes the top 10 cards from the deck and moves them to top the top of the 10 piles with a nice SKAction move action. I also have a pause function, which removes all the cards from the game and puts a dark gray overlay over the board, and then when called again it replaces the cards. the cards are a subclass of SKSpriteNode. the deal function works fine normally, but if I pause and then unpause the game, it no longer works. The code before and after the card.runAction(move) is excecuted, but the cards don't move.


my deal function (simplified)

func deal {
     for i in 0...9
            {
               x = cards.indexOf(topOfDeck!)! - i
                cards[x].column = i
                cards[x].row = topCardsOrdered[i].row + 1
              
                let move = SKAction.moveTo(CGPoint(x:topCardsOrdered[i].position.x, y: topCardsOrdered[i].position.y - verticalSpacingFaceUp[i]), duration: 0.2)
                cards[x].runAction(move, withKey: "dealAction")
            }
     }
              


my pause function

func pause() {
        if container.paused == false
        {
            container.paused = true
            self.addChild(grayFilter)
            for i in 0...103
            {
                cards[i].removeFromParent()
            }
        }
        else
        {
            container.paused = false
            grayFilter.removeFromParent()
            for i in 0...103
            {
                container.addChild(cards[i])
            }
            let move = SKAction.moveTo(CGPoint(x: 0, y: 0), duration: 1)
            cards[10].runAction(move)
        }
    }


I thought maybe there was a problem with the action finding the correct position, but I put a simple action to rotate the node in its place, and just like the move action that was only run if the game hadn't been paused yet. I have checked and all of the properties of each card are the same before and after the pause, and the rest of the game works as it should after being unpaused, so after two days of troubleshooting this I am lost.

You could try temporarily replacing these 'runAction' calls with simply setting the position, and see where the cards go.


However, line 20 of your pause function is odd. Why move only one of the cards at this point, and why that card?


I also wonder why you chose to remove the cards from their parent, rather than just hiding them (by setting their alpha to 0).

Oh, that one card was just for testing purposes (it doesn't work), I didn't realize it was still there. Hiding them would be a better option, I guess I just wasn't sure how to do that. I will try what you suggested and let you know.

Instead of line 20 specifiying a single node, shouldnt you be going through every child you've added and add the runAction to it?

Also, SpriteNodes have a property hidden which you can set = yes instead of changing Alphas.

SKAction no longer works after removing and re-adding SKSpriteNodes
 
 
Q