Jump to content

Rotating sprite body and sprite


seiyria
 Share

Recommended Posts

I'm having an insane amount of difficulty rotating a sprite body with a sprite, and I don't know if I'm doing it right. Since I want rotations to be "in tile", I first do the rotation and then I move the sprite around based on where it should be (ie, rotation of 90 degrees means it has to be moved vertically, -90 means it has to be pushed along the x axis). Then, after setting up some debug, I notice the sprite body is not in the same spot as the sprite, and any attempt to manually set x / y / width / height on the body was in vain. So I ended up trying this:

obj.body.polygon.rotate (-angle)*(Math.PI/180)

Well, this almost works. First off, I noticed that SAT and Phaser operate in different measures (Phaser - degrees, SAT - radians). Then I noticed that they rotated in different directions, so I had to make it negative to make it rotate the right direction. Now, the one part I can't get past, is that they rotate around different points (Phaser - bottom left, SAT - top left). 

 

Is there an easy way to rotate the sprite body too?

 

edit:

I should add that I also have tried to manually position the bounding box to no avail. 

Link to comment
Share on other sites

I'm also runnig in alot of difficulty with this issue. I'm trying to make a paddle game where you can bat falling fruit. So want to be able to rotate the paddle around a poitn with the user input.

 

obj.body.angularAcceleration is altered and the max values restrainted.

And this rotates the sprite as expected. But the physics body does not move or rotate to match.

 

The sprite angle is detected through obj.angle i think. Really quite confused by this.

Link to comment
Share on other sites

I forgot to mention I did come to a solution. Unfortunately it took a bit longer than I had expected, but there is the code I've got: 

obj.body.polygon.translate 0, -obj.heighyobj.body.polygon.rotate angle*Math.PI/180obj.body.polygon.translate 0, obj.height

It was modeled after some other code I had found on the forums. It's weird that it has to be translated though.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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