tomds Posted July 9, 2014 Share Posted July 9, 2014 Hi, I'm trying to overlay a few sprites on top of each other and make them move together as one body, using the P2 physics system. Basically it's meant to be two people sat on a canoe, and they can paddle independently of each other, and so are animated independently of each other. It seems a bit complicated to try and represent all the possible frames of animation with a single sprite, hence why I am wanting to overlay 3 sprites: 1 for the canoe and 2 for the people. The problem I'm having is keeping the people inside the canoe as it moves and rotates! I could give each sprite a separate body and apply the same physics rules to each, but I don't think this will work; really I need to the physics rules to apply only to the canoe, and have the people track the canoe's movement automatically. Is there an easy way to do this? Or am I doing it completely wrong? ThanksTom Link to comment Share on other sites More sharing options...
Antagonist Posted July 10, 2014 Share Posted July 10, 2014 you should use joints , to tie the phasic bodies together. Link to comment Share on other sites More sharing options...
lewster32 Posted July 10, 2014 Share Posted July 10, 2014 You can also put sprites in other sprites, so you can create a 'container' sprite with a body, then put your people inside:var canoe = game.add.sprite(0, 0, 'canoe');var person1 = game.add.sprite(0, 0, 'person1');var person2 = game.add.sprite(0, 0, 'person2')canoe.addChild(person1);canoe.addChild(person2);game.physics.enable(canoe, Phaser.Physics.P2);If you need to place the people behind the canoe, then create another top-level sprite and set the key to 'null', then add your people, then the canoe to that. Massemassimo, mauticom, horkoda and 2 others 5 Link to comment Share on other sites More sharing options...
tomds Posted July 14, 2014 Author Share Posted July 14, 2014 Thanks, you guys are the best! Added the people as children of the canoe sprite and it works - although I had to enable physics on the canoe before adding the people, otherwise they had a starting momentum on game load, and went shooting off to the side! Tom Link to comment Share on other sites More sharing options...
charlieRobinson Posted March 3, 2016 Share Posted March 3, 2016 On 7/10/2014 at 11:05 AM, lewster32 said: You can also put sprites in other sprites, so you can create a 'container' sprite with a body, then put your people inside: var canoe = game.add.sprite(0, 0, 'canoe');var person1 = game.add.sprite(0, 0, 'person1');var person2 = game.add.sprite(0, 0, 'person2')canoe.addChild(person1);canoe.addChild(person2);game.physics.enable(canoe, Phaser.Physics.P2); If you need to place the people behind the canoe, then create another top-level sprite and set the key to 'null', then add your people, then the canoe to that. I am trying to create a square from bitmapdata make it a sprite and add it to another sprite. But when I add it to another it disappears! Anyone know why this is? how do you make a square from bitmapdata and then add it as a child to another sprite? What am I missing? Thank you!! Link to comment Share on other sites More sharing options...
lewster32 Posted March 4, 2016 Share Posted March 4, 2016 If it's disappearing it may be because of its position. Display object positions are relative to their parent. This means that if the square is at 100, 100, and the sprite is also at 100, 100, when you add the square as a child of the sprite, it will be at 200, 200 relative to the screen - i.e. it'll instantly shift 100 pixels to the right, and 100 pixels down. Link to comment Share on other sites More sharing options...
Recommended Posts