Jump to content

[PIXI] sprite.worldTransform[2] => undefined


d13
 Share

Recommended Posts

Thank you for your replies!

 

I tried sprite.worldTransform.tx and sprite.worldTransform.ty and they're both giving me the same value: 

 

0

 

If the sprite is at in a container at 10,10 and the container is on the stage at 50,50, shouldn't the worldTransform.tx and worldTransform.ty be 60,60?

Or am I misunderstanding these values?

(I'm using Pixi 1.5.3)

 

In my current project I'm calculating the stage positions of sprites in a container like this:

 

stageX = sprite.x + sprite.parent.x;

stageY = sprite.y + sprite.parent.y;

 

But this only works for one nested level. 

Link to comment
Share on other sites

Make sure that at least one run of `updateTransform` has gone through the entire scene graph. Remember this matrix is updated each frame render not when you change position/rotation values. That means you have to let a frame or two pass by then check the value.

Thank you, I did not know this!

It works!! :)

Link to comment
Share on other sites

... but now that it works, I have a related question :)

Using the `worldTransform` values I sometimes see off-by-one inaccuracies in my collision detection functions.

(Using the parent x and y offsets is fine, and so are local x and y if the sprites are in the same coordinate space.)

 

Could this have something do with the order of evaluation in `updateTransform`? 

Link to comment
Share on other sites

... but now that it works, I have a related question :)

Using the `worldTransform` values I sometimes see off-by-one inaccuracies in my collision detection functions.

(Using the parent x and y offsets is fine, and so are local x and y if the sprites are in the same coordinate space.)

 

Could this have something do with the order of evaluation in `updateTransform`? 

 

Off-by-one as in if you add the tree yourself you get a different value than what is in the transform matrix?

Link to comment
Share on other sites

Off-by-one as in if you add the tree yourself you get a different value than what is in the transform matrix?

 

I think I know what's happening.

As you explained, `updateTransform` updates `worldTransform` each frame, not at the instant when a sprite's local x/y position is changed.

That means you can't accurately use `worldTransform.tx` and `worldTransform.tx` for collision detection and reaction because they contain the position values from the previous frame.

I am understanding this correctly?

Link to comment
Share on other sites

I think I know what's happening.

As you explained, `updateTransform` updates `worldTransform` each frame, not at the instant when a sprite's local x/y position is changed.

That means you can't accurately use `worldTransform.tx` and `worldTransform.tx` for collision detection and reaction because they contain the position values from the previous frame.

I am understanding this correctly?

 

That is correct.

Link to comment
Share on other sites

Great, now I know how this is all working.

I'll see if I can devise some other way of calculating immediate worldX and worldY co-ordinates that isn't too expensive.

... maybe by peering up through the parent/child hierarchy... I'll test that :)

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.

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

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...