erkro1 Posted January 1, 2016 Share Posted January 1, 2016 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: Normalhttp://i.imgur.com/V8FRJ3M.png Anchor 0.5http://i.imgur.com/xLoEpZi.png Angle 90http://i.imgur.com/x1YtRnn.png adamsko 1 Link to comment Share on other sites More sharing options...
rich Posted January 1, 2016 Share Posted January 1, 2016 You need to adjust their coordinates accordingly. Link to comment Share on other sites More sharing options...
erkro1 Posted January 1, 2016 Author Share Posted January 1, 2016 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 More sharing options...
rich Posted January 1, 2016 Share Posted January 1, 2016 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. adamsko 1 Link to comment Share on other sites More sharing options...
erkro1 Posted January 1, 2016 Author Share Posted January 1, 2016 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 More sharing options...
Recommended Posts