Jump to content

Getting global position of children


Recommended Posts

Hello. I've been trying to work on a project using Pixi.js and have hit a bit of a snag.


I've used addChild to add a sprite offset from another sprite, similar to a moon orbiting around a planet. This works fine for displaying as usual, however I now need the moon's position on the screen, in order to use the graphics module to draw some lines directly. However moon.position returns the local offset from the parent planet. Couldn't find anything in the documentation, and looking through the source I assume I have to use the sprite's worldTransform somehow. I don't know how nice that'd play with multiple levels of children, however.


Any help is appreciated.


EDIT: Of course, as soon as I post about it, I end up figuring it out by myself.


moon.worldTransform[2] is the x position, moon.worldTransform[5] is the y position.


A convenience function for getting the global position would be nice though, or at least a mention of worldTransform in the docs.

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...