Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Sprite randomly stuttering when velocity is set


vidhu
 Share

Recommended Posts

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

  • 4 months later...
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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...