Skip to content

Commit b4a30b8

Browse files
committed
Add callbacks on GameObjects
1 parent 41d7c4b commit b4a30b8

10 files changed

Lines changed: 100 additions & 39 deletions

File tree

src/gameobjects/GameObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ var GameObject = new Class({
254254
* @since 3.0.0
255255
*
256256
* @param {any} [shape] - A geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
257-
* @param {function} [callback] - A callback to be invoked when the Game Object is interacted with.
257+
* @param {HitAreaCallback} [callback] - A callback to be invoked when the Game Object is interacted with.
258258
* @param {boolean} [dropZone=false] - Should this Game Object be treated as a drop zone target?
259259
*
260260
* @return {Phaser.GameObjects.GameObject} This GameObject.

src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ var GameObject = require('../../GameObject');
1010
var GetBitmapTextSize = require('../GetBitmapTextSize');
1111
var Render = require('./DynamicBitmapTextRender');
1212

13+
/**
14+
* @callback DisplayCallback
15+
*
16+
* @param {object} display - [description]
17+
* @param {{topLeft:number,topRight:number,bottomLeft:number,bottomRight:number}} display.tint - [description]
18+
* @param {number} display.index - [description]
19+
* @param {number} display.charCode - [description]
20+
* @param {number} display.x - [description]
21+
* @param {number} display.y - [description]
22+
* @param {number} display.scale - [description]
23+
* @param {number} display.rotation - [description]
24+
* @param {[type]} display.data - [description]
25+
*/
26+
1327
/**
1428
* @classdesc
1529
* [description]
@@ -161,7 +175,7 @@ var DynamicBitmapText = new Class({
161175
* [description]
162176
*
163177
* @name Phaser.GameObjects.DynamicBitmapText#displayCallback;
164-
* @type {function}
178+
* @type {DisplayCallback}
165179
* @since 3.0.0
166180
*/
167181
this.displayCallback;
@@ -192,7 +206,7 @@ var DynamicBitmapText = new Class({
192206
* @method Phaser.GameObjects.DynamicBitmapText#setDisplayCallback
193207
* @since 3.0.0
194208
*
195-
* @param {function} callback - [description]
209+
* @param {DisplayCallback} callback - [description]
196210
*
197211
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
198212
*/
@@ -286,21 +300,6 @@ var DynamicBitmapText = new Class({
286300
return this;
287301
},
288302

289-
// {
290-
// local: {
291-
// x,
292-
// y,
293-
// width,
294-
// height
295-
// },
296-
// global: {
297-
// x,
298-
// y,
299-
// width,
300-
// height
301-
// }
302-
// }
303-
304303
/**
305304
* [description]
306305
*

src/gameobjects/blitter/Blitter.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ var Frame = require('../../textures/Frame');
1212
var GameObject = require('../GameObject');
1313
var List = require('../../structs/List');
1414

15+
/**
16+
* @callback BlitterFromCallback
17+
*
18+
* @param {Phaser.GameObjects.Blitter} blitter - [description]
19+
* @param {integer} index - [description]
20+
*/
21+
1522
/**
1623
* @classdesc
1724
* A Blitter Game Object.
@@ -44,7 +51,7 @@ var List = require('../../structs/List');
4451
* @extends Phaser.GameObjects.Components.Texture
4552
* @extends Phaser.GameObjects.Components.Transform
4653
* @extends Phaser.GameObjects.Components.Visible
47-
*
54+
*
4855
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. It can only belong to one Scene at any given time.
4956
* @param {number} [x=0] - The x coordinate of this Game Object in world space.
5057
* @param {number} [y=0] - The y coordinate of this Game Object in world space.
@@ -144,7 +151,7 @@ var Blitter = new Class({
144151
* @method Phaser.GameObjects.Blitter#createFromCallback
145152
* @since 3.0.0
146153
*
147-
* @param {function} callback - The callback to invoke after creating a bob. It will be sent two arguments: The Bob and the index of the Bob.
154+
* @param {BlitterFromCallback} callback - The callback to invoke after creating a bob. It will be sent two arguments: The Bob and the index of the Bob.
148155
* @param {integer} quantity - The quantity of Bob objects to create.
149156
* @param {string} [frame] - The Frame the Bobs will use. It must be part of the Blitter Texture.
150157
* @param {boolean} [visible=true] - [description]

src/gameobjects/lights/LightsManager.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ var Light = require('./Light');
99
var LightPipeline = require('../../renderer/webgl/pipelines/ForwardDiffuseLightPipeline');
1010
var Utils = require('../../renderer/webgl/Utils');
1111

12+
/**
13+
* @callback LightForEach
14+
*
15+
* @param {Phaser.GameObjects.Light} light - [description]
16+
*/
17+
1218
/**
1319
* @classdesc
1420
* [description]
@@ -28,7 +34,7 @@ var LightsManager = new Class({
2834
* [description]
2935
*
3036
* @name Phaser.GameObjects.LightsManager#lightPool
31-
* @type {array}
37+
* @type {Phaser.GameObjects.Light[]}
3238
* @default []
3339
* @since 3.0.0
3440
*/
@@ -38,7 +44,7 @@ var LightsManager = new Class({
3844
* [description]
3945
*
4046
* @name Phaser.GameObjects.LightsManager#lights
41-
* @type {array}
47+
* @type {Phaser.GameObjects.Light[]}
4248
* @default []
4349
* @since 3.0.0
4450
*/
@@ -48,7 +54,7 @@ var LightsManager = new Class({
4854
* [description]
4955
*
5056
* @name Phaser.GameObjects.LightsManager#culledLights
51-
* @type {array}
57+
* @type {Phaser.GameObjects.Light[]}
5258
* @default []
5359
* @since 3.0.0
5460
*/
@@ -155,7 +161,7 @@ var LightsManager = new Class({
155161
* @method Phaser.GameObjects.LightsManager#forEachLight
156162
* @since 3.0.0
157163
*
158-
* @param {function} callback - [description]
164+
* @param {LightForEach} callback - [description]
159165
*
160166
* @return {Phaser.GameObjects.LightsManager} This Lights Manager object.
161167
*/

src/gameobjects/particles/EmitterOp.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@ var GetEaseFunction = require('../../tweens/builders/GetEaseFunction');
1010
var GetFastValue = require('../../utils/object/GetFastValue');
1111
var Wrap = require('../../math/Wrap');
1212

13+
/**
14+
* The returned value sets what the property will be at the START of the particles life, on emit.
15+
* @callback EmitterOpOnEmitCallback
16+
*
17+
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
18+
* @param {string} key - [description]
19+
* @param {number} value - [description]
20+
*
21+
* @return {number} [description]
22+
*/
23+
24+
/**
25+
* The returned value updates the property for the duration of the particles life.
26+
* @callback EmitterOpOnUpdateCallback
27+
*
28+
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
29+
* @param {string} key - [description]
30+
* @param {float} t - The T value (between 0 and 1)
31+
* @param {number} value - [description]
32+
*
33+
* @return {number} [description]
34+
*/
35+
1336
/**
1437
* @classdesc
1538
* [description]
@@ -121,7 +144,7 @@ var EmitterOp = new Class({
121144
* [description]
122145
*
123146
* @name Phaser.GameObjects.Particles.EmitterOp#onEmit
124-
* @type {function}
147+
* @type {EmitterOpOnEmitCallback}
125148
* @since 3.0.0
126149
*/
127150
this.onEmit = this.defaultEmit;
@@ -130,7 +153,7 @@ var EmitterOp = new Class({
130153
* [description]
131154
*
132155
* @name Phaser.GameObjects.Particles.EmitterOp#onUpdate
133-
* @type {function}
156+
* @type {EmitterOpOnUpdateCallback}
134157
* @since 3.0.0
135158
*/
136159
this.onUpdate = this.defaultUpdate;

src/gameobjects/particles/ParticleEmitter.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ var StableSort = require('../../utils/array/StableSort');
2121
var Vector2 = require('../../math/Vector2');
2222
var Wrap = require('../../math/Wrap');
2323

24+
/**
25+
* @callback ParticleEmitterCallback
26+
*
27+
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
28+
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - [description]
29+
*/
30+
31+
/**
32+
* @callback ParticleDeathCallback
33+
*
34+
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
35+
*/
36+
2437
/**
2538
* @classdesc
2639
* [description]
@@ -400,7 +413,7 @@ var ParticleEmitter = new Class({
400413
* [description]
401414
*
402415
* @name Phaser.GameObjects.Particles.ParticleEmitter#emitCallback
403-
* @type {?function}
416+
* @type {?ParticleEmitterCallback}
404417
* @default null
405418
* @since 3.0.0
406419
*/
@@ -410,7 +423,7 @@ var ParticleEmitter = new Class({
410423
* [description]
411424
*
412425
* @name Phaser.GameObjects.Particles.ParticleEmitter#emitCallbackScope
413-
* @type {?object}
426+
* @type {?any}
414427
* @default null
415428
* @since 3.0.0
416429
*/
@@ -420,7 +433,7 @@ var ParticleEmitter = new Class({
420433
* [description]
421434
*
422435
* @name Phaser.GameObjects.Particles.ParticleEmitter#deathCallback
423-
* @type {?function}
436+
* @type {?ParticleDeathCallback}
424437
* @default null
425438
* @since 3.0.0
426439
*/
@@ -430,7 +443,7 @@ var ParticleEmitter = new Class({
430443
* [description]
431444
*
432445
* @name Phaser.GameObjects.Particles.ParticleEmitter#deathCallbackScope
433-
* @type {?object}
446+
* @type {?any}
434447
* @default null
435448
* @since 3.0.0
436449
*/
@@ -1534,7 +1547,7 @@ var ParticleEmitter = new Class({
15341547
* @method Phaser.GameObjects.Particles.ParticleEmitter#onParticleEmit
15351548
* @since 3.0.0
15361549
*
1537-
* @param {function} callback - [description]
1550+
* @param {ParticleEmitterCallback} callback - [description]
15381551
* @param {any} [context] - [description]
15391552
*
15401553
* @return {Phaser.GameObjects.Particles.ParticleEmitter} This Particle Emitter.
@@ -1566,7 +1579,7 @@ var ParticleEmitter = new Class({
15661579
* @method Phaser.GameObjects.Particles.ParticleEmitter#onParticleDeath
15671580
* @since 3.0.0
15681581
*
1569-
* @param {function} callback - [description]
1582+
* @param {ParticleDeathCallback} callback - [description]
15701583
* @param {any} [context] - [description]
15711584
*
15721585
* @return {Phaser.GameObjects.Particles.ParticleEmitter} This Particle Emitter.
@@ -1619,7 +1632,7 @@ var ParticleEmitter = new Class({
16191632
* @method Phaser.GameObjects.Particles.ParticleEmitter#forEachAlive
16201633
* @since 3.0.0
16211634
*
1622-
* @param {function} callback - [description]
1635+
* @param {ParticleEmitterCallback} callback - [description]
16231636
* @param {any} thisArg - [description]
16241637
*
16251638
* @return {Phaser.GameObjects.Particles.ParticleEmitter} This Particle Emitter.
@@ -1644,7 +1657,7 @@ var ParticleEmitter = new Class({
16441657
* @method Phaser.GameObjects.Particles.ParticleEmitter#forEachDead
16451658
* @since 3.0.0
16461659
*
1647-
* @param {function} callback - [description]
1660+
* @param {ParticleEmitterCallback} callback - [description]
16481661
* @param {any} thisArg - [description]
16491662
*
16501663
* @return {Phaser.GameObjects.Particles.ParticleEmitter} This Particle Emitter.

src/gameobjects/text/TextStyle.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ var MeasureText = require('./MeasureText');
1111

1212
// Key: [ Object Key, Default Value ]
1313

14+
/**
15+
* A custom function that will be responsible for wrapping the text.
16+
* @callback TextStyleWordWrapCallback
17+
*
18+
* @param {string} text - The string to wrap.
19+
* @param {Phaser.GameObjects.Text} textObject - The Text instance.
20+
*
21+
* @return {(string|string[])} Should return the wrapped lines either as an array of lines or as a string with
22+
* newline characters in place to indicate where breaks should happen.
23+
*/
24+
1425
var propertyMap = {
1526
fontFamily: [ 'fontFamily', 'Courier' ],
1627
fontSize: [ 'fontSize', '16px' ],
@@ -820,7 +831,7 @@ var TextStyle = new Class({
820831
* @method Phaser.GameObjects.Components.TextStyle#setWordWrapCallback
821832
* @since 3.0.0
822833
*
823-
* @param {function} callback - A custom function that will be responsible for wrapping the
834+
* @param {TextStyleWordWrapCallback} callback - A custom function that will be responsible for wrapping the
824835
* text. It will receive two arguments: text (the string to wrap), textObject (this Text
825836
* instance). It should return the wrapped lines either as an array of lines or as a string with
826837
* newline characters in place to indicate where breaks should happen.

src/gameobjects/text/static/Text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ var Text = new Class({
795795
* @method Phaser.GameObjects.Text#setWordWrapCallback
796796
* @since 3.0.0
797797
*
798-
* @param {function} callback - A custom function that will be responsible for wrapping the
798+
* @param {TextStyleWordWrapCallback} callback - A custom function that will be responsible for wrapping the
799799
* text. It will receive two arguments: text (the string to wrap), textObject (this Text
800800
* instance). It should return the wrapped lines either as an array of lines or as a string with
801801
* newline characters in place to indicate where breaks should happen.

src/gameobjects/zone/Zone.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ var Zone = new Class({
105105
/**
106106
* The displayed width of this Game Object.
107107
* This value takes into account the scale factor.
108-
*
108+
*
109109
* @name Phaser.GameObjects.Zone#displayWidth
110110
* @type {number}
111111
* @since 3.0.0
@@ -127,7 +127,7 @@ var Zone = new Class({
127127
/**
128128
* The displayed height of this Game Object.
129129
* This value takes into account the scale factor.
130-
*
130+
*
131131
* @name Phaser.GameObjects.Zone#displayHeight
132132
* @type {number}
133133
* @since 3.0.0
@@ -237,7 +237,7 @@ var Zone = new Class({
237237
* @since 3.0.0
238238
*
239239
* @param {object} shape - A Geometry shape instance, such as Phaser.Geom.Ellipse, or your own custom shape.
240-
* @param {function} callback - A function that will return `true` if the given x/y coords it is sent are within the shape.
240+
* @param {HitAreaCallback} callback - A function that will return `true` if the given x/y coords it is sent are within the shape.
241241
*
242242
* @return {Phaser.GameObjects.Zone} This Game Object.
243243
*/

src/input/InteractiveObject.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @param {number} x - [description]
1414
* @param {number} y - [description]
1515
* @param {Phaser.GameObjects.GameObject} gameObject - [description]
16+
*
17+
* @return {boolean} [description]
1618
*/
1719

1820
/**

0 commit comments

Comments
 (0)