JHook Posted July 22, 2014 Share Posted July 22, 2014 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 spritethis.sprite.frameName = 'fish10000'; // set framethis.game.physics.p2.enableBody(this.sprite, false); // enable physicsthis.sprite.body.setRectangle(115, 35, 0, 0); // create bodythis.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! Jonathan Link to comment Share on other sites More sharing options...
rich Posted July 22, 2014 Share Posted July 22, 2014 Is it just the debug that is out of place? I.e. the body is still correct and physics working properly, but the debug draw is out of sync? Link to comment Share on other sites More sharing options...
pandavigoureux29 Posted July 22, 2014 Share Posted July 22, 2014 Are you by any chance using a group to store your fish? This may be related to my (unsolved) problem here:http://www.html5gamedevs.com/topic/7917-p2-moving-a-group-doesnt-move-bodies-of-its-children/#entry47226 In my case the debug is right, as shown in my example here Mefteg 1 Link to comment Share on other sites More sharing options...
JHook Posted July 22, 2014 Author Share Posted July 22, 2014 @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 More sharing options...
Recommended Posts