mirror of
https://github.com/wassname/phaser.git
synced 2026-07-24 13:10:53 +08:00
Groups can now be added to other Groups as children via group.add() and group.addAt().
Groups now have an 'alive' property, which can be useful when iterating through child groups with functions like forEachAlive.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('ball', 'assets/sprites/pangball.png');
|
||||
game.load.image('arrow', 'assets/sprites/asteroids_ship.png');
|
||||
|
||||
}
|
||||
|
||||
var ballsGroup;
|
||||
var shipsGroup;
|
||||
|
||||
function create() {
|
||||
|
||||
ballsGroup = game.add.group();
|
||||
shipsGroup = game.add.group();
|
||||
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
// Create some randomly placed sprites in both Groups
|
||||
ballsGroup.create(game.rnd.integerInRange(0, 128), game.world.randomY, 'ball');
|
||||
shipsGroup.create(game.rnd.integerInRange(0, 128), game.world.randomY, 'arrow');
|
||||
}
|
||||
|
||||
// Now make the ships group a child of the balls group - so anything that happens to the balls group
|
||||
// will happen to the ships group too
|
||||
ballsGroup.add(shipsGroup);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
ballsGroup.x += 0.1;
|
||||
|
||||
// Because shipsGroup is a child of ballsGroup it has already been moved 0.1px by the line above
|
||||
// So the following line of code will make it appear to move twice as fast as ballsGroup
|
||||
shipsGroup.x += 0.1;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user