Sprite Kit - notifies that the node leaves the screen

Is there an event / notification in the Sprite Kit that tells me when a node leaves the screen? Suppose I want a colored circle to appear on top when it comes out of the screen below. This means that I need to know when it leaves the screen.

+1
source share
2 answers

The sprite set does not generate notifications when a sprite leaves the screen. You will need to add your own test. Here is an example ...

- (void) update:(NSTimerInterval)currentTime { CGPoint newPosition = CGPointMake(node.position.x, node.position.y); if (node.position.y > maxY+node.size.y/2) { newPosition.y = minY; } else if (node.position.y < minX-node.size.y/2) { newPosition.y = maxY; } if (node.position.x > maxX+node.size.x/2) { newPosition.x = minX; } else if (node.position.x < minX-node.size.x/2) { newPosition.x = maxX; } node.position = newPosition; 
+1
source

You will need to make sure, I think

 - (void)update:(NSTimeInterval)currentTime { if (node.position.y > screenHeight+nodeSize){ // need to define first, of course // do something like NSLog(); or [removeFromParent] or whatever =) } } 
+2
source

All Articles