Sprite Kit中是否有事件/通知可以告诉我节点何时离开屏幕?
假设我希望当彩色屏幕离开屏幕底部时在顶部显示一个彩色圆圈。这意味着我需要知道它何时离开屏幕。

最佳答案

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

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

关于ios - Sprite Kit-通知节点节点正在离开屏幕,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25033279/

10-14 23:04
查看更多