Sign in to follow this  
Zalon

Asteroids Movement for a group

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?

Share this post


Link to post
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);

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.