You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you have a sprite child of another sprite, child of another sprite child of a group, child of the world, the world property no longer calculates the correct x/y.
It may not work in different hierarchies as well but this hierarchy is used commonly in my game, hence I've done a lot of testing with it. I have a muzzle flash child of a gun sprite which is the child of a unit which is the child of a group which is the child of the world. That's:
The muzzle flash rotates to align with the gun and the gun rotates independently of the unit. The unit rotates relative to the group (which has no transforms on it) which is relative to the world. As the gun fires, I need to calculate the start x/y position (relative to the world) so I know where to start the bullet tween. Should be easy right? Just use the .world property on the muzzle flash (since the muzzle flash is right on top of where the bullet starts). Unfortunately, that doesn't work. It is affected by odd things, like movement of the camera and the world x/y never lands exactly on where the muzzle flash is. rotations might have something to do with it as well (gun is rotate, unit is rotated, etc). If I move the camera the start position of the bullet calculated literally moves to a point that seems relative to the camera. It's bizarre! Anyway, I've been trying to find workaround of this issue for the last two days, and keep going back and fourth. I've concluded there is something wrong going on inside Phaser when calculating the world x/y positions. Would appreciate it if someone could look into it.
Tested in 2.4.7, 2.6.0 and 2.6.1.
P.S. I have also tried adding the x/y of all the parent sprites to get the position relative to the world. While those results aren't affected by camera (like world.x/y), I don't think they take into account rotation as the bullets start far from the muzzle flash. If someone knows a formula that can calculate absolute x/y, taking rotation of children and parents into account, that would be immensely helpful.
The text was updated successfully, but these errors were encountered:
It depends what value you want. worldPosition, worldScale and worldRotation are all updated each frame, in the updateTransform method - until that point they will be either not set, or inaccurate (depending on how old they are).
If they are deeply nested then it needs a full scene graph update before the values are correct (i.e. you need to call game.stage.updateTransform()before checking any of those properties).
If you don't believe those properties contain the correct values then I need a code sample demonstrating it please.
Ugh this is so frustrating. A whole year later and I am still plagued by this issue.
sprite.worldPosition and sprite.world - appear to give you different coordinates but neither make any sense. They seem to be tied to the camera somehow because when you move the camera around, it alters the results.
All I want is to figure out a child's position in the world - not it's position relative to its parent.
When you have a sprite child of another sprite, child of another sprite child of a group, child of the world, the world property no longer calculates the correct x/y.
It may not work in different hierarchies as well but this hierarchy is used commonly in my game, hence I've done a lot of testing with it. I have a muzzle flash child of a gun sprite which is the child of a unit which is the child of a group which is the child of the world. That's:
sprite (muzzleflash) > sprite (gun) > sprite (unit) > group > world.
The muzzle flash rotates to align with the gun and the gun rotates independently of the unit. The unit rotates relative to the group (which has no transforms on it) which is relative to the world. As the gun fires, I need to calculate the start x/y position (relative to the world) so I know where to start the bullet tween. Should be easy right? Just use the .world property on the muzzle flash (since the muzzle flash is right on top of where the bullet starts). Unfortunately, that doesn't work. It is affected by odd things, like movement of the camera and the world x/y never lands exactly on where the muzzle flash is. rotations might have something to do with it as well (gun is rotate, unit is rotated, etc). If I move the camera the start position of the bullet calculated literally moves to a point that seems relative to the camera. It's bizarre! Anyway, I've been trying to find workaround of this issue for the last two days, and keep going back and fourth. I've concluded there is something wrong going on inside Phaser when calculating the world x/y positions. Would appreciate it if someone could look into it.
Tested in 2.4.7, 2.6.0 and 2.6.1.
P.S. I have also tried adding the x/y of all the parent sprites to get the position relative to the world. While those results aren't affected by camera (like world.x/y), I don't think they take into account rotation as the bullets start far from the muzzle flash. If someone knows a formula that can calculate absolute x/y, taking rotation of children and parents into account, that would be immensely helpful.
The text was updated successfully, but these errors were encountered: