2014-01-06 01:39:23 +00:00
|
|
|
// Here is a custom group
|
|
|
|
// It will automatically create 30 sprites of the given image when created.
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
MonsterGroup = function (game, image, action) {
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
Phaser.Group.call(this, game);
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
for (var i = 0; i < 30; i++)
|
|
|
|
{
|
|
|
|
var sprite = this.create(game.world.randomX, game.world.randomY, image);
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
if (action == 'bounce')
|
2013-11-25 13:12:03 +00:00
|
|
|
{
|
2014-01-06 01:39:23 +00:00
|
|
|
game.add.tween(sprite).to({ y: sprite.y - 100 }, 2000, Phaser.Easing.Elastic.Out, true, 0, 1000, true);
|
|
|
|
}
|
|
|
|
else if (action == 'slide')
|
|
|
|
{
|
|
|
|
game.add.tween(sprite).to({ x: sprite.x + 200 }, 4000, Phaser.Easing.Elastic.Out, true, 0, 1000, true);
|
2013-11-25 13:12:03 +00:00
|
|
|
}
|
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
}
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
};
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
MonsterGroup.prototype = Object.create(Phaser.Group.prototype);
|
|
|
|
MonsterGroup.prototype.constructor = MonsterGroup;
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
var customGroup1;
|
|
|
|
var customGroup2;
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
function preload() {
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
game.load.image('ufo', 'assets/sprites/ufo.png');
|
|
|
|
game.load.image('baddie', 'assets/sprites/space-baddie.png');
|
|
|
|
|
|
|
|
}
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
function create() {
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
customGroup1 = new MonsterGroup(game, 'ufo', 'bounce');
|
|
|
|
customGroup2 = new MonsterGroup(game, 'baddie', 'slide');
|
2013-11-25 13:12:03 +00:00
|
|
|
|
2014-01-06 01:39:23 +00:00
|
|
|
}
|