Jump to content

Weird behavior with sprite.body.drag


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):



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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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