Jump to content

Weird behavior with sprite.body.drag


rafaholiveira
 Share

Recommended Posts

After setting body.drag for a sprite, the sprite changes body.facing many times before stop.

 

Test (the animation for left and right changes with body.facing):

http://rafaholiveira.com.br/test-drag/

 

here is my code:

var game = new Phaser.Game(800, 600, Phaser.AUTO, "gameContainer", { preload: preload, create: create, update: update });var quad = null;function preload() {    game.load.spritesheet('quad_spsheet', "quad.png", 50, 50);}function create() {				    quad = game.add.sprite(200, 200, "quad_spsheet");    quad.animations.add("right_anim", [0]);    quad.animations.add("left_anim", [1]);    quad.body.maxVelocity.x = 250;}   function update(){    quad.body.acceleration.x = 0;    quad.body.drag.x = 250;    if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))    {        quad.body.acceleration.x = -150;    }    else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))    {	quad.body.acceleration.x = 150;    }    if (quad.body.facing == Phaser.LEFT)        quad.animations.play("left_anim");    else if (quad.body.facing == Phaser.RIGHT)        quad.animations.play("right_anim");}
Link to comment
Share on other sites

Hmm interesting, I suspect the values are jumping back/forth really fast (so the facing is changing accordingly). If you wouldn't mind, file it as a bug on github (with the above code) so we can queue it to be looked into in a bit more depth, but it may be the sort of thing that requires a custom workaround.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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