Smrdis Posted February 8, 2015 Share Posted February 8, 2015 Phaser provide few variants how to calc time elapsed since last frame, like game.time.elapsed or this.game.time.elapsedSince ect. But all that variants works badly %). For example, I want create moving sprite. It should be smooth and moving speed should not depend on device performance. Here simple code example:private mySprite : Phaser.Sprite;private update(): void{ var dt : number = this.game.time.elapsed; this.mySprite.x += dt * speed_const;}For some reason mySprite moving speed depends on FPS. If FPS drops down mySprite moves faster. So game.time.elapsed contain wrong value %). Another way:private mySprite : Phaser.Sprite;private lastTime : number = 0;private update() : void{ var tm : number = this.game.time.totalElapsedSeconds(); var dt: number = tm - this.lastTime; this.lastTime = tm; this.mySprite.x += dt * speed_const;}mySprite moving speed does not depend on FPS, but mySprite moves jerkily because sometime dt == 0. Link to comment Share on other sites More sharing options...
Dennis Posted February 9, 2015 Share Posted February 9, 2015 have you try this.game.time.physicsElapsed Link to comment Share on other sites More sharing options...
Smrdis Posted February 9, 2015 Author Share Posted February 9, 2015 As I understand physicsElapsed is just constant. this.desiredFps = 60;this.physicsElapsed = 1 / this.desiredFps; Link to comment Share on other sites More sharing options...
rich Posted February 9, 2015 Share Posted February 9, 2015 You're trying to implement a delta timer system on-top of an already delta-timed logic update game loop (that is why physicsElapsed is a constant, as the game loop is regulated already). Link to comment Share on other sites More sharing options...
Smrdis Posted February 9, 2015 Author Share Posted February 9, 2015 Thanks, Rich. Link to comment Share on other sites More sharing options...
Recommended Posts