I make a bunch of sprites from the gameScene and other objects, all by calling a function that creates instances of a subclass of SKSpriteNode.
eg, from GameScene, like this:
let sizee = CGSize(width: 100, height: 100)
let posi = CGPoint(x: 200, y: 300)
func createSprite(){
let new = Circle(color: SKColor.blue, size: sizee , position: posi)
addChild(new)
new.zPosition = 2
}
from within Circle, I remove each instance after its done a bit of animating:
import SpriteKit
class Circle: SKSpriteNode {
let fade = SKAction.fadeAlpha(to: 0.5, duration: 2)
let myScale = SKAction.scaleX(to: 3, duration: 2)
let die = SKAction.removeFromParent()
override init(texture: SKTexture?, color: UIColor, size: CGSize) {
super.init(texture: texture, color: color, size: size)
}
convenience init(color: UIColor, size: CGSize, position: CGPoint) {
self.init(color: color, size: size)
self.position = position
self.run(SKAction.sequence([fade, die]))
self.run(myScale)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Is this enough to ensure that these are getting released from memory?
Or do I have to do something else to flush them from the game world and memory?