您可以将增量时间应用于SKAction

时间:2015-06-14 01:36:31

标签: swift sprite-kit

我已经开始在游戏中注意到,当fps因为屏幕上有更多节点而关闭时,节点会开始移动,节点开始移动时会有一些波动。我用以下方式移动节点:

    let ran = Int(arc4random_uniform(1400));
    let monster = SKSpriteNode(texture: text)
    monster.position = CGPoint(x: ran, y: 800);

    let move = SKAction.moveTo(CGPointMake(monster.position.x, -100), duration: 2);
    let remove = SKAction.runBlock { () -> Void in
        score += 1;
        monster.removeFromParent()
    }
    monster.runAction(SKAction.sequence([move,remove]));

我可以使用增量时间来影响节点运动吗?我该怎么做呢?会有什么不同吗?

1 个答案:

答案 0 :(得分:0)

在为视图添加更多节点时,无法对FPS减慢做太多工作。运行您的应用的设备也决定了您的FPS。较新的型号具有更快的CPU。

要使用增量时间,您可以执行以下操作:

post "/chatContent"

如果您正在寻找Swift版本的代码,请查看之前的问答here

您不能在中途减速或加速SKAction。要调整移动速度,您必须通过应用CGVectorMake等物理力或更改其x,y位置来手动移动节点。

添加此属性:

-(void)update:(NSTimeInterval) currentTime {
    NSTimeInterval delta = currentTime - self.lastUpdateTime;
    self.lastUpdateTime = currentTime;
    // use the delta time to determine how much your sprites need to move to stay in sync.
}

然后在您的@property (nonatomic) NSTimeInterval lastUpdateTime; 方法中:

update

}

相关问题