Jump to content

What is the way Phaser3 uses to sync texture position with its Body position?


j.c
 Share

Recommended Posts

for example, `matter.add.image` this way I created a MatterImage to my scene, the texture is added to displayList, and the body is added to the world, but I have read the source code, I could not find any clue where Phaser set the texture position according to it's body position in every frame step?

I think other engine uses the way in the frame step to set sprite position by a bound matterBody?

I need to figure out how Phaser achieves this, thank you very much.

 

Link to comment
Share on other sites

23 hours ago, samme said:

See Phaser.Physics.Matter.Components.Transform.

all code are just set _tempVec2 and Body position, no sync code found in it.

I think _tempVec2 this variable must be used at somewhere for example in render pipleline, but still I can't find any clue.

Link to comment
Share on other sites

13 hours ago, samme said:

I'm not sure there's any syncing at all. I think the body's coordinates are mapped directly onto the transform coordinates.

emmm, yes, sorry I was stupid, I found in TextureTintPipeline.js:

spriteMatrix.applyITRS(sprite.x, sprite.y, sprite.rotation, sprite.scaleX, sprite.scaleY);

so in every frame this sprite.x returns body.x. so MatterXXXX class is actually a mixture of Sprite + Matter.Body.

thanks Samme

Link to comment
Share on other sites

by the way, I think there is no "dirty" concept in Phaser? so every frame the render gets the newest position from its body?

for example, in PIXI, there is dirty flag in the Sprite class, once you set x or y, the updateBounds flag set to true.

so in this case, if only its Body updated, the sprite's display will not change because Body update does not emit any event to notify the sprite to reset its dirty flag and then to update its bounds.

 

Link to comment
Share on other sites

  • 1 year later...
 Share

  • Recently Browsing   0 members

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