Jump to content

Sprite rotation also changes it's position


erkro1
 Share

Recommended Posts

When I change a sprite it's rotation with *.rotation, *.angle or *.pivot, it also changes the position because the center of the sprite will change.

 

I'm making a game with a grid and it makes my sprites fall out of their tiles, how can I prevent this?

 

Also here are some example pictures:

 

Normal


 

Anchor 0.5


 

Angle 90


 

 

Link to comment
Share on other sites

You need to adjust their coordinates accordingly.

 

What is the best way of doing that (like which parameters should I change)? I've tried manually setting the x and y, but it messes with a lot of other things I've written because the sprite will be on another place the object is.

Link to comment
Share on other sites

You can only change the x and y (or Sprite.position), nothing else changes the Sprites coordinates.

 

If you need the sprites to be able to rotate around their centre, then you'll need to use either anchor or pivot (rarely both) and adjust their coordinates, because they'll now be visually offset.

 

Alternatively this is where being a display list comes in handy. Use a parent sprite which can be positioned exactly at your grid coordinates, then have a child which is what gets rendered and rotated. That will always just be offset from its parents coordinates.

Link to comment
Share on other sites

You can only change the x and y (or Sprite.position), nothing else changes the Sprites coordinates.

 

If you need the sprites to be able to rotate around their centre, then you'll need to use either anchor or pivot (rarely both) and adjust their coordinates, because they'll now be visually offset.

 

Alternatively this is where being a display list comes in handy. Use a parent sprite which can be positioned exactly at your grid coordinates, then have a child which is what gets rendered and rotated. That will always just be offset from its parents coordinates.

 

I got it working with a child sprite with the rotation, thank you for solving my question!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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