Rotating things on object layer changes XY coordinates


(Jermccurdy) #1

When rotating objects on an object layer, the X and Y position will change. It looks like everything has a middle anchor, so the position shouldn’t change on rotation. It makes placing objects with varied rotations very frustrating.


(Thorbjørn Lindeijer) #2

In fact, the position is changing because the rotation origin matches the origin of the object, which is in the top-left for rectangles and botton-left for tile objects. So when the rotation tool is used to rotate an object around its center, it is necessary to change its position. At the moment Tiled does not support changing the origin of the objects.

But I do not understand why this makes placing objects with varied rotations frustrating. In the end it should not matter at all where Tiled puts the origin, since it can be relatively easily moved to somewhere else when loading the map. I’ve tried to explain one approach to this at http://forum.mapeditor.org/t/deer-need-for-x-and-y-to-be-the-center-of-the-object-instead-of-top-left-corner/150. Does that help you?


(Jermccurdy) #3

Why do objects pivot based on the center inside of tiled then? Doesn’t it make more sense to put the pivot at the actual origin of the object?


(Thorbjørn Lindeijer) #4

This would be very annoying, right? Also, what would you do in case of multiple selected objects then? Right now, it rotates around their collective visual center.


(pit) #5

Hi Bjorn and Jermccurdy,

I have, maybe silly, question. I am on Ubuntu and have Tiled version 0.9.1 and I cannot find where is functionality for rotating objects under object layer…

thanks,
Piotr


(Thorbjørn Lindeijer) #6

I think the question is not silly, but the answer is simple. Support for object rotation was added in Tiled 0.10. To upgrade to a more recent version of Tiled on Ubuntu I recommend using the daily builds available from https://launchpad.net/~mapeditor.org/+archive/ubuntu/tiled. In short:

sudo add-apt-repository ppa:mapeditor.org/tiled
sudo apt-get update
sudo apt-get install tiled-daily

(pit) #7

Hi Bjorn,

wow… looks amazing

I used Ubuntu Software Center, so that is reason why I did not get it.

Thanks for help !


(Thorbjørn Lindeijer) #8

I’m glad you like it. :-)

How did you make the quick screen capture?


(pit) #9

I am using two tools.

Fist is video screen capture Kazam, this is my second or third screen capture program and finally this is best for me. It does quite nice compression without any digging in settings.

Then I am loading screencast to QGifer and make gif, there are some nice options like add margins or width and height outputted gif.

both free on Linux :).


(Thorbjørn Lindeijer) #10

I played around with this a bit and it seems really nice indeed. One day I will use it!


(Sebastian) #11

Do you think that this bug will be fixed soon? I’m not sure if I really want to handle the shifted anchor point within my game code or wait for a fix.


(Thorbjørn Lindeijer) #12

@Sebastian If you mean the anchor point being top-left for rectangle objects but bottom-left for tile objects, that’s unfortunately just the way it is and it’s not a bug pending to be fixed.

It can be made consistent eventually, but this will be a change in the map format affecting everyone using Tiled. That means, such a change would make it possible to define the anchor point explicitly, while the default behavior would need to stay the same.


(Sebastian) #13

I see, thx for quick response @bjorn!


(Danilo Ganzella) #14

Oh god why.

Im very bad at trigonometry. After 3 hours I finally found out the algorithm to find the center:

Vector pos = new Vector(x+ ((sin(radians(rot)) + cos(radians(rot))) * height/2f),y+ ((sin(radians(rot)) - cos(radians(rot))) * height/2f));

ps. Does someone know the math behind this? I though that a simple sin/cos would suffice, but that was not the case.


(Stephen Lynx) #15

It makes sense to place objects using their center as their origin for games that use physics. I don’t think I ever seen a physics engine not use object’s centers for their origin.

You can add a map setting to use the object’s center for origin, just like all other map settings that already exist.
This would keep compatibility with older maps while allowing people to optionally use this feature so they wouldn’t have to re-calculate the object’s origin.


(Thorbjørn Lindeijer) #16

Yeah, that’s basically how it would be done. Though I think some people will need the option to override the origin per object anyway. Also, using the center for polygons and polylines will be problematic since it would change while editing the polygon. But those objects don’t use “width” and “height” properties anyway.

Adding support for centered anchor points is covered by the following issue:

https://github.com/bjorn/tiled/issues/560