Jump to content

Rotating a sprite around a point, but keeping orientation the same


kenray
 Share

Recommended Posts

I have a sprite that I need to move in an arc motion while still keeping it's orientation the same (so I can't use sprite.pivot and sprite.rotation AFAIK). So for example, if I have a sprite at 200,200 and it needs to pivot around a point at 200,400 for 90 degrees in a clockwise motion, it want it to end up at 400,400, with the sprite itself never having rotated during its journey.

 

 

Any ideas?

 

Link to comment
Share on other sites

you could rotate the sprite around its own center, then translate it out from the center and then rotate it the other direction - this is how you would achieve this using linear algebra

 

or you could follow jerome's suggestion and just do the sin/cos math

 

the latter will be faster, in general, as you can optimize it for the fewest operations. but the former may be easier if you prefer linear algebra (vectors and matrices) solutions. personally I'd go with the latter - it's simpler and easier

Link to comment
Share on other sites

Hmm... It just seems odd that there's a easy way to move a sprite from point A to point B in a line without rotation of the sprite (using game.physics.velocityFromAngle), and an easy way to move a sprite in an arc with rotation (with sprite.pivot and sprite.rotation), but there's not an easy way to move a sprite in an arc without rotation... 

 

Is this something that's addressed in Phaser 1.2?

 

(FYI: What I'm trying to accomplish is the equivalent of an animation of someone tossing a pizza box from offscreen, it comes in from the left edge (with the box parallel to the ground), moves downward in an arc, and stops when it hits the ground. I don't need need to have it adjust its orientation at all or even bounce when it hits the ground (yet)... I'm just trying to get the animation to work properly first.) 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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