• Content Count

  • Joined

  • Last visited

  1. My guess is it doesn't stop colliding, which is why you never get another onBeginContact signal after the first one. Write a onEndContact to see if thats the case. If it is, your object body is probably not placed right. You might also want to enable body.debug to see the body. Edit, keep in mind these events fire when you collide one of the vertices. Therefore vertice positions are important.
  2. Here is a more detailed explanation. You have guy, let guy = game.add.sprite(0,0,'guy') And you want to give him a sword let sword = game.add.sprite(0,0,'sword') You would normally do, guy.addChild(sword) However, if you want sword to have a body, addChild doesn't work. Workaround is; You create a 'ghost' sprite without a body. let ghostSprite = game.add.sprite(0,0,'ghostSprite'); Make it invisible so it doesn't block our real sword. ghostSprite.visible = false; Add it as a child to our guy guy.addChild('ghostSprite'); Now, our ghostSprite is perfectly following&rotating with our guy. All we need to do is 'attach' sword to the ghostSprite. sword.body.x =; sword.body.y =; sword.body.rotation = ghostSprite.worldRotation; We assign rotation & position to the body because it controls sprite pos&rot. If you assign it to the sprite, you will see sprite trying to move but constantly 'pulling back' to the body. So, always assign to the body, not to the sprite. You might also want to set body.debug = true; to debug any weird behaviours in the future. Thats about it. Hit me up if you cant get it to work.
  3. So I have been searching a solution for this for 2 days now. I have a character with physics body. This character has sprites attached to it with addChild(). Arms, sword, cloak, range indicator. Range indicator also has a body (only used as sensor/trigger ). However as I found out addChild doesn't work on physics bodies. Sprites move together but I can get Range Indicator's body to move with them. It pretty much sits in the corner. Since addChild() is no go for physics bodies, is there anything else I can use with this? Really trying to avoid writing a custom function to make the body follow me but running out of options here. EDIT: Found a workaround for weird child behaviour with bodies. Added another invisible sprite and made it child to my body. this.rangePositioner = game.add.sprite(0, 0, 'rangeBlack'); this.rangePositioner.anchor.set(0.5); this.rangePositioner.pivot.set(0, 40); this.addChild(this.rangePositioner); Take its world position with ( rangePositioner.position returns 0 ) then set it to my child body.position. I had to dig for some time before I realized returns a point. I would expect it to be named something like worldPoint. Anyways I hope this helps someone.