Jump to content

Player attachments and grouping help


zades
 Share

Recommended Posts

I'm playing some problems getting my player to show up correctly.  My game is top down and my characters have components like weapon, body, feet, and so on and they must be rendered in a particular order. The controls use WASD to move and the mouse to aim (make the character face a direction).  I also use the P2 engine.  I'm having a lot of problems getting everything to play nicely with each other.

 

My current solution is to have the delete the parts on the attachments that would overlap and connect them via sprite.addchild.

 

Ok anyways, theres what I've tried so far and their problems.

 

Sprite.addchild:

This works, it keeps physics and everything, but I use the body as the parent (as it has the only physics polygon I care about) and everything else is attached it, and what happens is that all the child renders above the parent so that's a no go, unless someone can tell me how to change it.

 

Using groups

I want the rotations of the character to interact physically with the enviroment, and currently I'm not sure how to do that.  I know you can set all properties of everything in the group with setall but I'm not sure if you can change something like call sprite.body.rotateleft() on all the child and have the rotate about the same point.

 

Using an empty sprite as the base group and attach everything else on it.  

Everything starts falling everything and I have no idea what's going on :(

 

I just want it to work with the requirements above (movement, rotation, render order).

 

 

Link to comment
Share on other sites

The empty sprite way is the best way to approach this - enable the body on the empty sprite first and then add the child sprites. If you enable the body after adding them, it will recursively add bodies to all of the children as well by default (the third parameter in game.physics.p2.enable specifies whether to apply it recursively or not)

Link to comment
Share on other sites

The empty sprite way is the best way to approach this - enable the body on the empty sprite first and then add the child sprites. If you enable the body after adding them, it will recursively add bodies to all of the children as well by default (the third parameter in game.physics.p2.enable specifies whether to apply it recursively or not)

 

Will this work if I have different physics bodies for the other parts as well?  Like say the character have its hands outstretched so it has a physics body component to it.  If I add this to the empty body, would it work?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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