Mariusz Posted September 11, 2014 Share Posted September 11, 2014 Hello there. I've been playing with the P2 physics engine and I hit a brick wall. If I try to enable P2 body on a sprite that is already rotated, the physics body will create a body rectangle that matches the sprite's rotation AND set the sprite's rotation to 0. I made the following gif to illustrate the issue: http://www.gfycat.com/AdolescentBruisedCuscusThe scale of the dynamically created sprite seems to be preserved perfectly fine, it's just the rotation that's been baffling me. I looked briefly into phaser.js, but couldn't pin it down... Could somebody explain to me what's going on? Thanks in advanceMariusz Link to comment Share on other sites More sharing options...
Wavertron Posted September 12, 2014 Share Posted September 12, 2014 If the order isnt crucial in your game, the easy fix is to enable P2 first, then use sprite.body.angle only. Dont use sprite.angleOtherwise sprite.angle set before P2 enabled seems to be acting like a permanent angle offset and that will probably cause all sorts of headaches. Link to comment Share on other sites More sharing options...
Mariusz Posted September 12, 2014 Author Share Posted September 12, 2014 Hey Rudy, thanks for the response. What I want to be able to do is enable the user to start drawing a line upon left mouse button click and keep manipulating the shape until the button is released. Once the user is happy with the length and angle, they will release the button and, at that point, I want to assign a physics body to the object that will acquire all the aforementioned properties, i.e. the length and the angle. So yes, to address your question, the order is crucial in this case. Unless there is a better way to approach this problem? Edit: My bad. I actually put some thought into Rudy's idea and it works perfectly fine. The sprite is manipulated and upon click release, I store the desired rotation, reset the sprite's rotation to zero and then apply it using sprite.body.angle. Link to comment Share on other sites More sharing options...
Recommended Posts