j.c Posted August 19, 2018 Share Posted August 19, 2018 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 More sharing options...
j.c Posted August 19, 2018 Author Share Posted August 19, 2018 in short, when Matter.Body updates, how does Phaser know I need to update my display's position, rotation etc? Link to comment Share on other sites More sharing options...
samme Posted August 19, 2018 Share Posted August 19, 2018 See Phaser.Physics.Matter.Components.Transform. Link to comment Share on other sites More sharing options...
j.c Posted August 20, 2018 Author Share Posted August 20, 2018 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 More sharing options...
samme Posted August 20, 2018 Share Posted August 20, 2018 I'm not sure there's any syncing at all. I think the body's coordinates are mapped directly onto the transform coordinates. Link to comment Share on other sites More sharing options...
j.c Posted August 21, 2018 Author Share Posted August 21, 2018 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 More sharing options...
j.c Posted August 23, 2018 Author Share Posted August 23, 2018 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 More sharing options...
roberto257 Posted November 15, 2019 Share Posted November 15, 2019 @j.c Can you explain how you implemented this? I am having the same issue Link to comment Share on other sites More sharing options...
Recommended Posts