[英]Is there any way to check if an SKSpriteNode has been removed from parent?
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. 我正在尝试检查是否已从屏幕上删除此SKSpriteNode来实现一段代码(如果有的话),但我似乎无法弄清楚。
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. 我有什么可以做的,以测试何时将其从父级删除。 Ie something along the lines of "
If (player hasLeftScene)
or (player hasBeenRemovedFromParent)
" or something? 即类似于“
If (player hasLeftScene)
或(player hasBeenRemovedFromParent)
”之类的东西吗?
I also tried testing for when the player.position.y > 568 (4-inch display) but it didn't work either. 我还尝试了测试player.position.y> 568(4英寸显示屏)的时间,但是它也不起作用。
Check for node.parent. 检查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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.