I'm trying to check if this SKSpriteNode has been removed from the screen to implement a piece of code if it has but I can't seem to figure it out.
My code;
if (player.position.y > self.frame.size.height) {
NSLog(@"out of frame");
[self runAction:[SKAction sequence:@[
[SKAction waitForDuration:0.5],
[SKAction runBlock:^{
levelMenu *mainMenu = [[levelMenu alloc] initWithSize:self.size];
[self.view presentScene:mainMenu transition:[SKTransition fadeWithDuration:0.6]];
}],
]]];
}
But this isn't working.
Is there anything I could do to test for when it's been removed from the parent. I.e. something along the lines of "If (player hasLeftScene)or(player hasBeenRemovedFromParent)" or something?
I also tried testing for when the player.position.y > 568 (4-inch display) but it didn't work either.
Check for node.parent. It is nil if it has no parent (was removed from one).
if (node.parent) {
// node has parent, was not removed
} else {
// node does not have parent, was removed
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With