简体   繁体   English

有什么方法可以检查SKSpriteNode是否已从父级移除?

[英]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.

相关问题 如何检查是否已窃听SKSpriteNode - How to check if an SKSpriteNode has been tapped 检查对象是否已从NSCache中删除的最佳方法? - Best way to check if objects have been removed from NSCache? 移除父级后,CDVViewController仍在执行JS - CDVViewController still executing JS after parent has been removed iOS-将ViewController从父控制器中移除后,是否将其释放? - iOS - Will the ViewController be deallocated after it's been removed from the parent controller? 有什么方法可以检测`UnsafeMutablePointer` 已被解除分配吗? - Any way to detect `UnsafeMutablePointer` has been deallocated? 有没有办法检查UIImage是否已解压缩? - Is there a way to check if a UIImage has been decompressed? iOS-更新已从应用商店中删除的应用 - iOS - Update an app that has been removed from the app store Invariant Violation:ViewPagerAndroid 已从 React Native 中移除 - Invariant Violation: ViewPagerAndroid has been removed from React Native 有什么办法可以在Swift中访问SKSpriteNode之类的属性? - Is there any way to access a property like SKSpriteNode in Swift? 有没有什么办法可以让我的自定义类继承自SKSpriteNode,而不是像SKNode那样触动节点 - Is there any way to get touched node not as SKNode but my custom class derived from SKSpriteNode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM