forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObjectFactory.js
More file actions
106 lines (68 loc) · 3.31 KB
/
Copy pathGameObjectFactory.js
File metadata and controls
106 lines (68 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Phaser.GameObjectFactory = function (game) {
this.game = game;
this.world = this.game.world;
};
Phaser.GameObjectFactory.prototype = {
game: null,
world: null,
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @returns {Sprite} The newly created sprite object.
*/
sprite: function (x, y, key, frame) {
return this.world.add(new Phaser.Sprite(this.game, x, y, key, frame));
},
/**
* Create a new Sprite with specific position and sprite sheet key that will automatically be added as a child of the given parent.
*
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @returns {Sprite} The newly created sprite object.
*/
child: function (parent, x, y, key, frame) {
var child = this.world.add(new Phaser.Sprite(this.game, x, y, key, frame));
parent.addChild(child);
return child;
},
/**
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
*
* @param obj {object} Object the tween will be run on.
* @param [localReference] {bool} If true the tween will be stored in the object.tween property so long as it exists. If already set it'll be over-written.
* @return {Phaser.Tween} The newly created tween object.
*/
tween: function (obj, localReference) {
return this.game.tweens.create(obj, localReference);
},
group: function (parent, name) {
return new Phaser.Group(this.game, parent, name);
},
audio: function (key, volume, loop) {
return this.game.sound.add(key, volume, loop);
},
tileSprite: function (x, y, width, height, key, frame) {
return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
},
text: function (x, y, text, style) {
return this.world.add(new Phaser.Text(this.game, x, y, text, style));
},
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
return this.world.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
},
graphics: function (x, y) {
return this.world.add(new Phaser.Graphics(this.game, x, y));
},
emitter: function (x, y, maxParticles) {
return this.game.particles.add(new Phaser.Particles.Arcade.Emitter(this.game, x, y, maxParticles));
},
bitmapText: function (x, y, text, style) {
return this.world.add(new Phaser.BitmapText(this.game, x, y, text, style));
},
};