Jump to content

Get coordinates of transformed container in pixijs


Recommended Posts

Hi everyone, Hi Ivan, 

First of all thanks to Ivan for answering all our questios without loosing your mind ;).

What I have is a  sprite (ship) with child container (weapon anchor). Now I want to draw a line (laser) from that container to another sprite (foe). 

The problem is, I cannot get the global coords of the container, but only the local ones. The workaround with getBounds() seems to return local x/y coordinates as well

  			var anchorWeapon = getByName(sprite.children, 'anchorWeapon'); // get the container for the anchorWeapon
            var bounds = anchorWeapon.getBounds(); // width and height should be 0 
            laser.points = [bounds.x, bounds.y, foe.x, foe.y];

// in function call:
 			laser.moveTo(laser.points[0], laser.points[1]);
    		laser.lineTo(laser.points[2], laser.points[3]);


I tried to make the line a child of the container itself, but then I cannot use the coords of the foe to line to because we are in local context.

What would be the best way to solve this?


Thanks a heap!




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