Jump to content

Local to Global Question


Recommended Posts

Hi @enpu

I'm still working on my tiles inside container level. I've manged to get the interactivity and masks working, but now I have one more issue.

I'm moving a container around with a bunch of tiles in it. When I click a tile, I would like to add it to the parent container, at the same position it is currently visible on screen.

The problem is that it is adding it at the co-ordinates of the container it was inside originally.

Is there any local to global function, to make this easier?

Thank you in advance for any tips :)

Link to comment
Share on other sites

If you are moving your sprite from container to another (and both's world position is other than 0,0), you might need to convert your sprite position first to world position, then change it's parent and then convert it back to local position.

sprite.toWorldPosition(sprite.position); // Convert to world position
sprite.addTo(container); // Change parent
sprite.toWorldPosition(sprite.position, true); // Convert to local position


Link to comment
Share on other sites


I have a 768x768 sprite ('baseBoard') and it's anchor is in the center. I've placed some more 'baseBoard' sprites inside the main sprite to extend the board to the left and right.

The offset is exactly half of 768x768, so it looks like I should be keeping the anchor top left if I want to avoid it.

I pretty sure this is the reason, my logic on this was just a little flawed - thanks heaps for the help!

Link to comment
Share on other sites

Hi @enpu

I did notice something different, the sprite moved into the new container is in a slightly diff position.

I however still need to use the offset to make it work (I'm pretty sure this is my fault), but it's the same offset as before, which is strange.

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.

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.
  • Create New...