vidhu Posted August 13, 2015 Share Posted August 13, 2015 I have a small sprite and I set its velocity.y=200 so it moves down. This works however, sometimes it moves smooth as silk. The other times it stutters a lot. I have no clue why this happens. Its like the frame rates drop to around 20fps from 60fps Here is my code for this simple this. What am I doing wrong and how can I fix it?var SimpleGame = (function () { function SimpleGame() { this.game = new Phaser.Game(800, 400, Phaser.AUTO, 'content', { preload: this.preload, create: this.create, update: this.update }); } SimpleGame.prototype.preload = function () { this.game.load.image('logo', 'Sprites/icon.png'); }; SimpleGame.prototype.create = function () { //Create Sprite this.speed = 133; this.game.stage.backgroundColor = 0xffffff; this.logo = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'logo'); this.logo.position.set(200, 50); this.game.physics.arcade.enable(this.logo); //Set velocity this.logo.body.velocity.y = this.speed; }; SimpleGame.prototype.update = function () { if (this.logo.position.y >= 400) { this.logo.body.velocity.y = -this.speed; } else if (this.logo.position.y <= 0) { this.logo.body.velocity.y = this.speed; } }; return SimpleGame;})();window.onload = function () { var game = new SimpleGame();};You can also test it here http://chest.vidhucraft.com/PhaserTest/ to see the stuttering Link to comment Share on other sites More sharing options...
imLeyenda Posted December 15, 2015 Share Posted December 15, 2015 Same issue here, any solution?. Greetings Link to comment Share on other sites More sharing options...
Batzi Posted December 16, 2015 Share Posted December 16, 2015 What if you do this insteadif(condition) this.logo.body.velocity.y -= this.speed;else this.logo.body.velocity.y += this.speed; Link to comment Share on other sites More sharing options...
san40511 Posted December 16, 2015 Share Posted December 16, 2015 you've set sprite anchor to center. and that's why cropped the half SimpleGame.prototype.update = function () { if (this.logo.position.y >= 400-this.logo.height/2) { this.logo.body.velocity.y = -200; } else if (this.logo.position.y <= this.logo.height/2) { this.logo.body.velocity.y = 200; } };About stutters. Everything works fine for me. Link to comment Share on other sites More sharing options...
nobody Posted December 16, 2015 Share Posted December 16, 2015 Try:- Use CANVAS and not AUTO (WebGL is slow in Firefox) Note that Phaser uses physicstime and not the real time to render things. If for example firefox is loading another tab, the animation will stutter. Link to comment Share on other sites More sharing options...
Recommended Posts