It is my understanding that SKSpriteNodes that have been added to the SKScene will linger there until removeFromParent(), or any of the other remove methods are called.
I haven't touched SpriteKit for 2 months, and that's what I remember it to be. But for some reason, today when I was programming, I realized something odd; I was looking at my node count and it was not being increased even though I am doing a .repeatActionForever
that keeps instantiating a new SKSpriteNode that runs across the screen. There are no remove
calls anywhere in the code. Here's the block of code that creates the SKSpriteNode:
//function in GameScene
func spawnEnemy() {
let enemy = SKSpriteNode(imageNamed: "enemy")
enemy.position = CGPoint(x: size.width + enemy.size.width/2, y: size.height/2)
let actionMove = SKAction.moveToX(-enemy.size.width/2, duration: 2.0)
enemy.runAction(actionMove)
}
//inside update()
runAction(SKAction.repeatActionForever(SKAction.runBlock(spawnEnemy))
Here's a gif of what the simulator showed: http://i.imgur.com/c8eyFDE.gif
I was under the impression that the stampede of old lady in dresses would linger off the screen and the node count for continue to build up, but for some reason, the node count stays constant at 42 nodes, as if the nodes that are off screen are automatically removed.
Again, I have no remove calls anywhere.