Jump to content

Sprite + P2 body alignment issue in 2.0.7


Recommended Posts

I've been working on a game in 2.0.5 and upgraded to 2.0.7 today. Unfortunately some of my sprites are no longer aligned with my p2 bodies after the upgrade. I've read through the changelog but haven't found any clues to what might be causing this. I have a couple screenshots of each version to explain what I'm seeing.


2.0.5 - You can see that the fish sprite is aligned with it's p2 body correctly. I also added debug.spritebounds for the fish and bucket... oddly enough debug.spritebounds for the bucket isn't correct, but that never caused an issue.




2.0.7 - The fish sprite is now way out of alignment with the p2 body but debug.spritebounds still shows the correct location. The bucket's body is still correct. As the body moves the fish will move with it. 




Addition Information that might help:


- The fish and bucket sprites are loaded together in a spritesheet with an atlas JSON file exported from flash, like so:


this.load.atlas('gameAssets', 'images/game_assets.png', 'images/game_assets.json');


- The fish sprites are created like:


this.sprite = this.game.add.sprite(845, 280, 'gameAssets'); // create sprite

this.sprite.frameName = 'fish10000'; // set frame

this.game.physics.p2.enableBody(this.sprite, false); // enable physics

this.sprite.body.setRectangle(115, 35, 0, 0); // create body

this.sprite.anchor.setTo(0.5, 0.5); // set anchor


- The bucket sprite has an animation that has already played in these screenshots and the spritebounds in the 2.0.7 screenshot align correctly with the largest frame of the animation


- In the shared spritesheet the bucket sprite is the default image. It seems that some coordinates are getting set to work with the bucket, but are not updated with I set the sprite's frame to the fish


- There are multiple fish in the spritesheet and the result is the same for all fish


- If I export a new spritesheet with JUST the fish, the bodies are lined up.



Any help tracking down a fix for this would be awesome.  Thanks!










Link to comment
Share on other sites

@rich - The debug is in the correct location, it's the sprite that is out of place. In the game you can click and drag the fish to drop them in the bucket. Clicking the fish sprite doesn't work, but when I turn on the p2 debug I can click the bodies and drag them. I had a small break through last night after posting this. I found that the issue is fixed if I specify the correct frame when i first create the sprite instead of changing the frame after it's been created:


this.sprite = this.game.add.sprite(845, 280, 'gameAssets', 'fish10000');


Is there some sort of size that is saved or passed to p2 when the sprite is first created that is happening in 2.0.7, but wasn't happening in 2.0.5? Specifying the fish frame when I first instantiate the sprite works, but seems like it should work in either order.


@pandavigoureux29 - It is being added to a group, but the group isn't repositioned.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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