Not rotating from sprite origin

Recommended Posts

I am making a car racing game. When i rotate  the car, it doesen't rotate well. It is rotating in a weird way. I did set the origin to the 0,0 with following code in order to make it match with the tiled editor origin. But, after that, the rotation is wrong.

player1 = this.physics.add.sprite(500, 500, 'car1').setOrigin(0 , 0)


Before start rotating:


After be rotating for a while:


I put the game code in the attachment.

Thank you in advance.

Share this post

Link to post
Share on other sites

Sorry, i believe that the explanation of my problem wasn't clear. I think that if the car rotates from its top-left corner it will be a wrong behaviour when you are playing. So i want it to rotate from its 0.5,0.5 position. The problem is when i import the position of the elements from tiled editor.

I have prepared this example:

In the example i have two cars. Both are right positioned in the tiled editor. In the tiled editor, both are just after the whilte line, in its center.


But when i import the json generated with tiled to phaser, i must use setOrigin(0,0) to maintain the right location. In my online example, i didn't use setOrigin(0,0) for the second car, so it is wrong positioned:


But if i change the origin to the 0,0 point, the rotation is not working fine. It is not rotating from its center and i believe it is a wrong behaviour when you are playing.

I did put the game with the tiled editor map in the attachments.

Thank you in advance.

Share this post

Link to post
Share on other sites

yeah, rotating things in tiled is a bad idea normally. As it doesn't translate very well. I had the same problem with walls in my map. I had thought i could could copy sections of my map in tiled, and rotate them for faster map making, but in phaser they came out all wrong. Instead of changing your cars origin to 0,0 to get it where you want, you should figure out the offset from it's intended position. 

so for example in your picture above where you didnt change the origin to 0,0 and it's in the wrong place, add half the width and half the height to the x and y positions and it should be where you want it to be.

Share this post

Link to post
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.

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.


  • Recently Browsing   0 members

    No registered users viewing this page.