I'm building a platformer, and I'm trying too learn about being efficient with memory and cpu cycles. Is there an efficient way to handle sprites that are off screen?
I guess the idea is, only handle the sprites on screen or close to it, all other sprites can be unconsidered to free up the handling that those sprites would take.
I have an array of all my sprites, so my first thought was look through them all and see if the camera, contains each one... If so add them to the screen as a child. If camera doesn't contain the sprite, then remove it from it's parent...
The issue I'm having, is that my character disappears even on screen, and I can't move him... Am I going about this wrong?
Thanks for any advice!!!
Update: "I'm not at my computer now, so syntax may be a little off"
for sprite in allSprites {
if camera.contains(sprite) {
sprite.removefromparent()
self.addChild(sprite)
}
else {
sprite.removefromparent()
}
}
When I get home I can update it to accurate code, and print the view and scene size.