|
1 | | -window.onload = function() { |
| 1 | +// Here is a custom group |
| 2 | +// It will automatically create 30 sprites of the given image when created. |
2 | 3 |
|
3 | | - // Here is a custom group |
4 | | - // It will automatically create 30 sprites of the given image when created. |
| 4 | +MonsterGroup = function (game, image, action) { |
5 | 5 |
|
6 | | - MonsterGroup = function (game, image, action) { |
| 6 | + Phaser.Group.call(this, game); |
7 | 7 |
|
8 | | - Phaser.Group.call(this, game); |
| 8 | + for (var i = 0; i < 30; i++) |
| 9 | + { |
| 10 | + var sprite = this.create(game.world.randomX, game.world.randomY, image); |
9 | 11 |
|
10 | | - for (var i = 0; i < 30; i++) |
| 12 | + if (action == 'bounce') |
11 | 13 | { |
12 | | - var sprite = this.create(game.world.randomX, game.world.randomY, image); |
13 | | - |
14 | | - if (action == 'bounce') |
15 | | - { |
16 | | - game.add.tween(sprite).to({ y: sprite.y - 100 }, 2000, Phaser.Easing.Elastic.Out, true, 0, 1000, true); |
17 | | - } |
18 | | - else if (action == 'slide') |
19 | | - { |
20 | | - game.add.tween(sprite).to({ x: sprite.x + 200 }, 4000, Phaser.Easing.Elastic.Out, true, 0, 1000, true); |
21 | | - } |
22 | | - |
| 14 | + game.add.tween(sprite).to({ y: sprite.y - 100 }, 2000, Phaser.Easing.Elastic.Out, true, 0, 1000, true); |
| 15 | + } |
| 16 | + else if (action == 'slide') |
| 17 | + { |
| 18 | + game.add.tween(sprite).to({ x: sprite.x + 200 }, 4000, Phaser.Easing.Elastic.Out, true, 0, 1000, true); |
23 | 19 | } |
24 | 20 |
|
25 | | - }; |
| 21 | + } |
26 | 22 |
|
27 | | - MonsterGroup.prototype = Object.create(Phaser.Group.prototype); |
28 | | - MonsterGroup.prototype.constructor = MonsterGroup; |
| 23 | +}; |
29 | 24 |
|
30 | | - var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create }); |
| 25 | +MonsterGroup.prototype = Object.create(Phaser.Group.prototype); |
| 26 | +MonsterGroup.prototype.constructor = MonsterGroup; |
31 | 27 |
|
32 | | - var customGroup1; |
33 | | - var customGroup2; |
| 28 | +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create }); |
34 | 29 |
|
35 | | - function preload() { |
| 30 | +var customGroup1; |
| 31 | +var customGroup2; |
36 | 32 |
|
37 | | - game.load.image('ufo', 'assets/sprites/ufo.png'); |
38 | | - game.load.image('baddie', 'assets/sprites/space-baddie.png'); |
39 | | - |
40 | | - } |
| 33 | +function preload() { |
41 | 34 |
|
42 | | - function create() { |
| 35 | + game.load.image('ufo', 'assets/sprites/ufo.png'); |
| 36 | + game.load.image('baddie', 'assets/sprites/space-baddie.png'); |
| 37 | + |
| 38 | +} |
43 | 39 |
|
44 | | - customGroup1 = new MonsterGroup(game, 'ufo', 'bounce'); |
45 | | - customGroup2 = new MonsterGroup(game, 'baddie', 'slide'); |
| 40 | +function create() { |
46 | 41 |
|
47 | | - } |
| 42 | + customGroup1 = new MonsterGroup(game, 'ufo', 'bounce'); |
| 43 | + customGroup2 = new MonsterGroup(game, 'baddie', 'slide'); |
48 | 44 |
|
49 | | -}(); |
| 45 | +} |
0 commit comments