Jump to content

Asteroids Movement for a group


Zalon
 Share

Recommended Posts

Hello,

 

I've been playing around with the asteroids movement from the phaser examples.

I then decided that I would try to recreate the example with a group instead of a single sprite, so I would have a ship base with 2 attached wings. However, since a group doesn't have a body, there is no way to move the group using acceleration and angularVelocity. If I instead move the parts, the group coordinates will not follow, so how would I go about creating the same kind of movement for a group?

Link to comment
Share on other sites

Groups can't have bodies, but sprites can, and you can add things to sprites using addChild - so you can do it this way:

var ship = game.add.sprite(0, 0, 'ship');var leftWing = game.add.image(0, 0, 'leftwing');leftWing.anchor.x = 1; // anchor the left wing from the right-hand sidevar rightWing = game.add.image(0, 0, 'rightwing');ship.addChild(leftWing);ship.addChild(rightWing);game.physics.arcade.enable(ship);
Link to comment
Share on other sites

  • 2 weeks later...

I don't think you can - however you can create a blank sprite and then put things in it and reorder them as needed:

var container = game.add.sprite(0, 0);var ship = game.add.image(0, 0, 'ship');var leftWing = game.add.image(0, 0, 'leftWing');var rightWing = game.add.image(0, 0, 'rightWing');container.addChild(leftWing);container.addChild(rightWing);container.addChild(ship);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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