Reputation: 918
I have created a "SPriteKitButton" SKNode subclass in a separate Swift file to use in SpriteKit to make custom button-like objects. I initialize a new button like so:
self.homeButton = SpriteKitButton(buttonUnpressedImage: "homeUnpressed.png", buttonPressedImage: "homePressed.png", buttonName: "homeButton", scale: 1, buttonAction: returnHome)
self.addChild(homeButton)
The button works great, but when I use presentScene to change scenes, the SpriteKitButton subclass is not being removed from memory. I am using the contentsOfFile method to set the textures in the subclass. I call
homeButton.removeFromParent
in willMoveFromView, but after testing I have found that my buttons are staying in memory and adding a small ~1-2 mb with each scene change.
I'm not experienced with using subclassed objects in SpriteKit, so how would I make sure my custom buttons get deleted when the scene is changed?
Thanks in advance!
Upvotes: 2
Views: 114
Reputation: 8720
self.homeButton = nil
Use this if you are using strong references
Upvotes: 3