Is there a way to check when a SKSpriteNode
/ SKNode
is onscreen (i.e. visible) I have a large scrolling background where I am spawning mobs, but I want to limit their animations and sounds if they are not visible. Is there a way to do this, I could write something in the update loop but I wanted to see if there was anything I could test before I start querying mob positions every frame?
Asked
Active
Viewed 481 times
3

fuzzygoat
- 26,573
- 48
- 165
- 294
-
Are you trying to avoid checking each sprite's position from the update method to see if they are in the screen maybe like this CGRectContainsRect([[UIScreen mainScreen]bounds], yourSprite.frame)? Is it the update method that is causing the scrolling background to move? – Bokoskokos Feb 12 '14 at 23:02
-
Checking position of the node is the only way I know to achieve that – Andrey Gordeev Feb 13 '14 at 04:05
-
Did you find a better way than checking each frame bounds in the update method? Since the SpriteKit documentation says that nodes outside of the scene's visible area "are ignored by the renderer" I was hoping we could more easily enumerate those nodes somehow? – Pieter May 28 '14 at 14:09
-
As far as I am aware there is no mechanism in the SDK currently to quickly access nodes that are either on-screen or off-screen. The only way I know is to loop through all the nodes in the scene and check their positions one by one. Maybe WWDC 2014 next week will change this. – fuzzygoat May 29 '14 at 10:08
1 Answers
0
I think you are doing this wrong. You should stick to the MVC pattern. As such, you only have data/points that are moving in a large area and in update method, if any data is within screen area, only would you draw them. If it is out, remove them.

GeneCode
- 7,545
- 8
- 50
- 85