Well, I made a rectangle made of polygons that had its first corner somewhere in the screen that is NOT 0,0.
Then I added a child to it, and set it to 0,0, and it ended on 0,0 of the whole screen.
Then I moved the rectangle, and the child moved too.
My guess is: for shape objects, their 0,0 is the 0,0 of their parent, so if you draw away from their 0,0, their "anchor" ends not inside the actual shape.
Yet I must ask, anyone has clear rules of how reference points and nested objects work? Corona SDK was a nightmare in relation to that (it had some bugs, and their system in general was greatly annoying).
Comments
The only exception is Bitmap, because it can use setAnchorPoint, which relatively to its dimensions changes the reference point.
And if you use Shape, you can actually choose where to draw the 0,0 coordinate, either inside or outside the Shape.
You can either draw as:
but we can also draw it in the center
So when you use setPosition method, you actually move the 0,0 coordinate to a specified coordinate.
What might seem confusing that each Sprite internally has it's own coordinate.
Let's consider this code:
And the we provide the position of Bitmap, but it's not relative to stage's coordinates, because Bitmap is inside Sprite, thus Bitmap positions is relative to Sprite's internal coordinates.
So if Sprite's 0,0 is positioned at 100,100, and we position Bitmap at -50,-50 inside Sprite, then relative to stage, Bitmap will actually be at 50, 50 coordinate.
To find out where Bitmap is relative to other parent, you can use local to global method:
Now another scenario, what if we want to position Bitmap at 75, 75 global stage coordinates, and don't want to calculate, what this position will be inside the Sprite's coordinates. Then we can use globalToLocal.
So we simply retrieve this x and y coordinates (hint which will be -25, -25)and set them to the Bitmap (which is inside Sprite). Thus Bitmap is position 75, 75 coordinate relatively to the stage.
Hope that helps
Likes: speeder_kidoteca
It could go into blog post, it could go into wiki, it could go into docs section or it could go into Ultimate Guide or (
https://bitbucket.org/IntoItGames/gideros-display
https://play.google.com/store/apps/developer?id=Into-It+Games
http://appstore.com/LidiaMaximova