swift - Can you apply delta time to an SKAction -
i've started notice in game i'm making fps goes down more nodes on screen, nodes start move little choppiness them. move nodes with:
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]));
can use delta time effect nodes movements? how do this? make difference?
you cannot fps slowing down add more nodes view. device running app determines fps. newer models have faster cpu.
to use delta time can this:
-(void)update:(nstimeinterval) currenttime { nstimeinterval delta = currenttime - self.lastupdatetime; self.lastupdatetime = currenttime; // use delta time determine how sprites need move stay in sync. }
if looking swift version of code, @ previous q&a here.
you cannot slow down or speed skaction in mid run. adjust speed of movement have move node manually either applying physics force such cgvectormake or changing x,y positions.
add property:
@property (nonatomic) nstimeinterval lastupdatetime;
then in update
method:
-(void)update:(cftimeinterval)currenttime { nstimeinterval delta = currenttime - self.lastupdatetime; self.lastupdatetime = currenttime; // sanity check if(delta > 1) delta = 0; float distancetomovepersecond = 5.0f; float numberofframespersecond = 60.0f; float xposition = ((distancetomovepersecond/numberofframespersecond) * delta) * 100; mynode0.position = cgpointmake(mynode0.position.x+xposition, mynode0.position.y);
}
Comments
Post a Comment