Jump to content

Flipping sprite removes body overlap collision detection


BatteryAcid
 Share

Recommended Posts

I have a sprite that animates a walk that "dies" when it comes into contact with a bullet.   The bullet(s) are just placed on the screen which "overlap" the body of the bad guy, and he "dies".

Flipping the sprite's X scale to -1 causes the overlap collision detection to fail for the bullet/badguy.  Below is the relevant code, any ideas?  Possible bug?

this.game.load.spritesheet('badguy-walk', 'images/bad-guy-walk.png', 160, 239);

// ...

var badGuyGroup = game.add.group();
badGuyGroup.enableBody = true;
badGuyGroup.physicsBodyType = Phaser.Physics.ARCADE;

var badguy = badGuyGroup.create(400, 400, "badguy-walk");
badguy.scale.setTo(-1, 1); // -1 Breaks collision, 1 works
badguy.animations.add("badGuyWalk");
badguy.animations.play("badGuyWalk", 30, true);

// ... overlap detection method doesn't fire
// the bullet group is a common physics enabled group of sprites
this.game.physics.arcade.overlap(
  badGuyGroup, this.bullets.getBulletGroup(), this.badGuyHit, null, this);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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