d13 Posted June 11, 2014 Share Posted June 11, 2014 Hello, I'm getting `undefined` with these values: sprite.worldTransform[2]sprite.worldTransform[5]According to this thread, they should return the DisplayObject's globalX and globalY positions: http://www.html5gamedevs.com/topic/1962-getting-global-position-of-children/ Am I making a mistake somewhere? Quote Link to comment Share on other sites More sharing options...
enpu Posted June 12, 2014 Share Posted June 12, 2014 I think that has changed. Trysprite.worldTransform.txsprite.worldTransform.ty Quote Link to comment Share on other sites More sharing options...
xerver Posted June 12, 2014 Share Posted June 12, 2014 I think that has changed. Trysprite.worldTransform.txsprite.worldTransform.ty Correct, we are using objects for worldTransform now not arrays. Quote Link to comment Share on other sites More sharing options...
d13 Posted June 15, 2014 Author Share Posted June 15, 2014 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. Quote Link to comment Share on other sites More sharing options...
enpu Posted June 16, 2014 Share Posted June 16, 2014 Is your container and sprite visible? Quote Link to comment Share on other sites More sharing options...
d13 Posted June 16, 2014 Author Share Posted June 16, 2014 Is your container and sprite visible?Yes Quote Link to comment Share on other sites More sharing options...
xerver Posted June 16, 2014 Share Posted June 16, 2014 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. d13 1 Quote Link to comment Share on other sites More sharing options...
d13 Posted June 16, 2014 Author Share Posted June 16, 2014 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!! Quote Link to comment Share on other sites More sharing options...
d13 Posted June 16, 2014 Author Share Posted June 16, 2014 ... 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`? Quote Link to comment Share on other sites More sharing options...
xerver Posted June 17, 2014 Share Posted June 17, 2014 ... 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? Quote Link to comment Share on other sites More sharing options...
d13 Posted June 17, 2014 Author Share Posted June 17, 2014 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? Quote Link to comment Share on other sites More sharing options...
xerver Posted June 17, 2014 Share Posted June 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
d13 Posted June 17, 2014 Author Share Posted June 17, 2014 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.