繁体   English   中英

Sprite Kit - 节点离开屏幕的通知程序

[英]Sprite Kit - Notifier that a node is leaving the screen

Sprite Kit中是否有事件/通知告诉我节点何时离开屏幕? 让我们说当我离开屏幕底部时,我想要一个彩色圆圈出现在顶部。 这意味着我需要知道它何时离开屏幕。

你需要自己检查我认为,

- (void)update:(NSTimeInterval)currentTime {

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

当精灵离开屏幕时,精灵工具包不会生成通知。 您需要添加自己的测试。 这是一个例子......

- (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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM