Jump to content

Different player movement speed in different browsers


v0van1981
 Share

Recommended Posts

Bug? In IE 11 movement speed two times less than Firefox / Chrome

var Player = (function (_super) {    __extends(Player, _super);    function Player(game, x, y) {        _super.call(this, game, x, y, 'simon', 0);        this.anchor.setTo(0.5, 0);        this.animations.add('walk', [0, 1, 2, 3, 4], 10, true);        this.game.physics.arcade.enableBody(this);        game.add.existing(this);    }    Player.prototype.update = function () {        this.body.velocity.x = 0;        if (this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {            this.body.velocity.x = -150;            this.animations.play('walk');            if (this.scale.x == 1) {                this.scale.x = -1;            }        } else if (this.game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {            this.body.velocity.x = 150;            this.animations.play('walk');            if (this.scale.x == -1) {                this.scale.x = 1;            }        } else {            this.animations.frame = 0;        }    };    return Player;})(Phaser.Sprite);

code from http://www.photonstorm.com/phaser/advanced-phaser-and-typescript-projects

Link to comment
Share on other sites

Hi v0van1981,

 

Is your Player.prototype.update() function called directly from requestAnimationFrame() as part of your render loop? If so, you've tied your player movement directly to your frame rate i.e. if the frame rate drops, your player will slow down. (I've just spotted the following in the linked article: "Once the sprite is added to the game world its update function will be called every frame.")

 

This article describes some techniques about how to separate out sprite movement from frame rate.

 

Thanks,

 

Vince.

Link to comment
Share on other sites

Hi v0van1981,

 

Is your Player.prototype.update() function called directly from requestAnimationFrame() as part of your render loop? If so, you've tied your player movement directly to your frame rate i.e. if the frame rate drops, your player will slow down. (I've just spotted the following in the linked article: "Once the sprite is added to the game world its update function will be called every frame.")

 

This article describes some techniques about how to separate out sprite movement from frame rate.

 

Thanks,

 

Vince.

 

I do no know. It is internal Phaser's loop. But from http://docs.phaser.io/Phaser.Physics.Arcade.Body.html

velocityThe velocity in pixels per second sq. of the Body.
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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