iOS SKSpriteNode - 离开屏幕 [英] iOS SKSpriteNode - Leave screen

查看:20
本文介绍了iOS SKSpriteNode - 离开屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以从 Parent 中删除具有左区域边界的 SKSpriteNode?

Is there any way to remove from Parent a SKSpriteNode that has left area bounds?

例如:

-(void)didBeginContact:(SKPhysicsContact *)contact
{
    firstNode = (SKSpriteNode *)contact.bodyA.node;
    if (firstNode.position.y<0) {
        [firstNode removeFromParent];
    }
}

只要给我指出正确的方向.是通过检查其矩形来枚举更新方法,还是您可以应用它们的操作.我浏览了文档似乎找不到它,但我认为这将是一个简单的实现,因为它可以节省内存

Just point me in the right direction. Is it the update method enumerate through checking their rects or is their an action you can apply. I have gone through the documentation can't seem to find it but I would have thought it would be an easy implement since it saves memory

推荐答案

更新方法是可以做到的:

Update method is where you can do it alright:

- (void)update:(NSTimeInterval)currentTime {
    //remove any nodes named "yourNode" that make it off screen
    [self enumerateChildNodesWithName:@"yourNode" usingBlock:^(SKNode *node, BOOL *stop) {

        if (node.position.x < 0){
            [node removeFromParent];
        }
    }];
}

请注意,删除节点并不能保证释放内存!!

Though note that removing nodes doesn't guarantee freeing up memory!!

这篇关于iOS SKSpriteNode - 离开屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆