簡體   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