Skip to content

Commit f30218d

Browse files
committed
Add callbacks on Physics
1 parent 8fdedab commit f30218d

6 files changed

Lines changed: 54 additions & 41 deletions

File tree

src/physics/arcade/ArcadePhysics.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ var ArcadePhysics = new Class({
144144
*
145145
* @param {Phaser.GameObjects.GameObject|array} object1 - The first object or array of objects to check. Can be any Game Object that has an Arcade Physics Body.
146146
* @param {Phaser.GameObjects.GameObject|array} object2 - The second object or array of objects to check. Can be any Game Object that has an Arcade Physics Body.
147-
* @param {function} [overlapCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter.
148-
* @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then `overlapCallback` will only be called if this callback returns `true`.
147+
* @param {ArcadePhysicsCallback} [overlapCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter.
148+
* @param {ArcadePhysicsCallback} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then `overlapCallback` will only be called if this callback returns `true`.
149149
* @param {object} [callbackContext] - The context in which to run the callbacks.
150150
*
151151
* @return {boolean} True if an overlap occurred otherwise false.
@@ -167,8 +167,8 @@ var ArcadePhysics = new Class({
167167
*
168168
* @param {Phaser.GameObjects.GameObject|array} object1 - The first object or array of objects to check. Can be any Game Object that has an Arcade Physics Body.
169169
* @param {Phaser.GameObjects.GameObject|array} object2 - The second object or array of objects to check. Can be any Game Object that has an Arcade Physics Body.
170-
* @param {function} [collideCallback=null] - An optional callback function that is called if the objects collide. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter.
171-
* @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`.
170+
* @param {ArcadePhysicsCallback} [collideCallback=null] - An optional callback function that is called if the objects collide. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter.
171+
* @param {ArcadePhysicsCallback} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`.
172172
* @param {object} [callbackContext] - The context in which to run the callbacks.
173173
*
174174
* @return {boolean} True if a collision occurred otherwise false.

src/physics/arcade/Collider.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var Class = require('../../utils/Class');
1919
* @param {boolean} overlapOnly - [description]
2020
* @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for collision.
2121
* @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for collision.
22-
* @param {function} collideCallback - The callback to invoke when the two objects collide.
23-
* @param {function} processCallback - The callback to invoke when the two objects collide. Must return a boolean.
22+
* @param {ArcadePhysicsCallback} collideCallback - The callback to invoke when the two objects collide.
23+
* @param {ArcadePhysicsCallback} processCallback - The callback to invoke when the two objects collide. Must return a boolean.
2424
* @param {object} callbackContext - The scope in which to call the callbacks.
2525
*/
2626
var Collider = new Class({
@@ -88,7 +88,7 @@ var Collider = new Class({
8888
* [description]
8989
*
9090
* @name Phaser.Physics.Arcade.Collider#collideCallback
91-
* @type {function}
91+
* @type {ArcadePhysicsCallback}
9292
* @since 3.0.0
9393
*/
9494
this.collideCallback = collideCallback;
@@ -97,7 +97,7 @@ var Collider = new Class({
9797
* [description]
9898
*
9999
* @name Phaser.Physics.Arcade.Collider#processCallback
100-
* @type {function}
100+
* @type {ArcadePhysicsCallback}
101101
* @since 3.0.0
102102
*/
103103
this.processCallback = processCallback;

src/physics/arcade/Factory.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ var Factory = new Class({
6565
*
6666
* @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for collision.
6767
* @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for collision.
68-
* @param {function} collideCallback - The callback to invoke when the two objects collide.
69-
* @param {function} processCallback - The callback to invoke when the two objects collide. Must return a boolean.
68+
* @param {ArcadePhysicsCallback} collideCallback - The callback to invoke when the two objects collide.
69+
* @param {ArcadePhysicsCallback} processCallback - The callback to invoke when the two objects collide. Must return a boolean.
7070
* @param {object} callbackContext - The scope in which to call the callbacks.
7171
*
7272
* @return {Phaser.Physics.Arcade.Collider} The Collider that was created.
@@ -84,8 +84,8 @@ var Factory = new Class({
8484
*
8585
* @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for overlap.
8686
* @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for overlap.
87-
* @param {function} collideCallback - The callback to invoke when the two objects collide.
88-
* @param {function} processCallback - The callback to invoke when the two objects collide. Must return a boolean.
87+
* @param {ArcadePhysicsCallback} collideCallback - The callback to invoke when the two objects collide.
88+
* @param {ArcadePhysicsCallback} processCallback - The callback to invoke when the two objects collide. Must return a boolean.
8989
* @param {object} callbackContext - The scope in which to call the callbacks.
9090
*
9191
* @return {Phaser.Physics.Arcade.Collider} The Collider that was created.

src/physics/arcade/World.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,9 @@ var World = new Class({
565565
*
566566
* @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for collision.
567567
* @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for collision.
568-
* @param {function} collideCallback - The callback to invoke when the two objects collide.
569-
* @param {function} processCallback - The callback to invoke when the two objects collide. Must return a boolean.
570-
* @param {object} callbackContext - The scope in which to call the callbacks.
568+
* @param {ArcadePhysicsCallback} [collideCallback] - The callback to invoke when the two objects collide.
569+
* @param {ArcadePhysicsCallback} [processCallback] - The callback to invoke when the two objects collide. Must return a boolean.
570+
* @param {object} [callbackContext] - The scope in which to call the callbacks.
571571
*
572572
* @return {Phaser.Physics.Arcade.Collider} The Collider that was created.
573573
*/
@@ -592,9 +592,9 @@ var World = new Class({
592592
*
593593
* @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for overlap.
594594
* @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for overlap.
595-
* @param {function} collideCallback - The callback to invoke when the two objects overlap.
596-
* @param {function} processCallback - The callback to invoke when the two objects overlap. Must return a boolean.
597-
* @param {object} callbackContext - The scope in which to call the callbacks.
595+
* @param {ArcadePhysicsCallback} [collideCallback] - The callback to invoke when the two objects overlap.
596+
* @param {ArcadePhysicsCallback} [processCallback] - The callback to invoke when the two objects overlap. Must return a boolean.
597+
* @param {object} [callbackContext] - The scope in which to call the callbacks.
598598
*
599599
* @return {Phaser.Physics.Arcade.Collider} The Collider that was created.
600600
*/
@@ -865,7 +865,7 @@ var World = new Class({
865865
*
866866
* @param {Phaser.Physics.Arcade.Body} body1 - [description]
867867
* @param {Phaser.Physics.Arcade.Body} body2 - [description]
868-
* @param {function} processCallback - [description]
868+
* @param {ArcadePhysicsCallback} processCallback - [description]
869869
* @param {object} callbackContext - [description]
870870
* @param {boolean} overlapOnly - [description]
871871
*
@@ -1249,9 +1249,9 @@ var World = new Class({
12491249
*
12501250
* @param {Phaser.GameObjects.GameObject} object1 - [description]
12511251
* @param {Phaser.GameObjects.GameObject} object2 - [description]
1252-
* @param {function} overlapCallback - [description]
1253-
* @param {function} processCallback - [description]
1254-
* @param {object} callbackContext - [description]
1252+
* @param {ArcadePhysicsCallback} [overlapCallback] - [description]
1253+
* @param {ArcadePhysicsCallback} [processCallback] - [description]
1254+
* @param {object} [callbackContext] - [description]
12551255
*
12561256
* @return {boolean} [description]
12571257
*/
@@ -1272,9 +1272,9 @@ var World = new Class({
12721272
*
12731273
* @param {Phaser.GameObjects.GameObject} object1 - [description]
12741274
* @param {Phaser.GameObjects.GameObject} object2 - [description]
1275-
* @param {function} collideCallback - [description]
1276-
* @param {function} processCallback - [description]
1277-
* @param {object} callbackContext - [description]
1275+
* @param {ArcadePhysicsCallback} [collideCallback] - [description]
1276+
* @param {ArcadePhysicsCallback} [processCallback] - [description]
1277+
* @param {object} [callbackContext] - [description]
12781278
*
12791279
* @return {boolean} [description]
12801280
*/
@@ -1295,8 +1295,8 @@ var World = new Class({
12951295
*
12961296
* @param {Phaser.GameObjects.GameObject} object1 - [description]
12971297
* @param {Phaser.GameObjects.GameObject} object2 - [description]
1298-
* @param {function} collideCallback - [description]
1299-
* @param {function} processCallback - [description]
1298+
* @param {ArcadePhysicsCallback} collideCallback - [description]
1299+
* @param {ArcadePhysicsCallback} processCallback - [description]
13001300
* @param {object} callbackContext - [description]
13011301
* @param {boolean} overlapOnly - [description]
13021302
*
@@ -1356,8 +1356,8 @@ var World = new Class({
13561356
*
13571357
* @param {Phaser.GameObjects.GameObject} object1 - [description]
13581358
* @param {Phaser.GameObjects.GameObject} object2 - [description]
1359-
* @param {function} collideCallback - [description]
1360-
* @param {function} processCallback - [description]
1359+
* @param {ArcadePhysicsCallback} collideCallback - [description]
1360+
* @param {ArcadePhysicsCallback} processCallback - [description]
13611361
* @param {object} callbackContext - [description]
13621362
* @param {boolean} overlapOnly - [description]
13631363
*
@@ -1434,8 +1434,8 @@ var World = new Class({
14341434
*
14351435
* @param {Phaser.GameObjects.GameObject} sprite1 - [description]
14361436
* @param {Phaser.GameObjects.GameObject} sprite2 - [description]
1437-
* @param {function} collideCallback - [description]
1438-
* @param {function} processCallback - [description]
1437+
* @param {ArcadePhysicsCallback} collideCallback - [description]
1438+
* @param {ArcadePhysicsCallback} processCallback - [description]
14391439
* @param {object} callbackContext - [description]
14401440
* @param {boolean} overlapOnly - [description]
14411441
*
@@ -1469,8 +1469,8 @@ var World = new Class({
14691469
*
14701470
* @param {Phaser.GameObjects.GameObject} sprite - [description]
14711471
* @param {Phaser.GameObjects.Group} group - [description]
1472-
* @param {function} collideCallback - [description]
1473-
* @param {function} processCallback - [description]
1472+
* @param {ArcadePhysicsCallback} collideCallback - [description]
1473+
* @param {ArcadePhysicsCallback} processCallback - [description]
14741474
* @param {object} callbackContext - [description]
14751475
* @param {boolean} overlapOnly - [description]
14761476
*
@@ -1532,8 +1532,8 @@ var World = new Class({
15321532
*
15331533
* @param {Phaser.GameObjects.Group} group - [description]
15341534
* @param {Phaser.Tilemaps.DynamicTilemapLayer|Phaser.Tilemaps.StaticTilemapLayer} tilemapLayer - [description]
1535-
* @param {function} collideCallback - [description]
1536-
* @param {function} processCallback - [description]
1535+
* @param {ArcadePhysicsCallback} collideCallback - [description]
1536+
* @param {ArcadePhysicsCallback} processCallback - [description]
15371537
* @param {object} callbackContext - [description]
15381538
* @param {boolean} overlapOnly - [description]
15391539
*
@@ -1572,8 +1572,8 @@ var World = new Class({
15721572
*
15731573
* @param {Phaser.GameObjects.GameObject} sprite - [description]
15741574
* @param {Phaser.Tilemaps.DynamicTilemapLayer|Phaser.Tilemaps.StaticTilemapLayer} tilemapLayer - [description]
1575-
* @param {function} collideCallback - [description]
1576-
* @param {function} processCallback - [description]
1575+
* @param {ArcadePhysicsCallback} collideCallback - [description]
1576+
* @param {ArcadePhysicsCallback} processCallback - [description]
15771577
* @param {object} callbackContext - [description]
15781578
* @param {boolean} overlapOnly - [description]
15791579
*
@@ -1671,8 +1671,8 @@ var World = new Class({
16711671
*
16721672
* @param {Phaser.GameObjects.Group} group1 - [description]
16731673
* @param {Phaser.GameObjects.Group} group2 - [description]
1674-
* @param {function} collideCallback - [description]
1675-
* @param {function} processCallback - [description]
1674+
* @param {ArcadePhysicsCallback} collideCallback - [description]
1675+
* @param {ArcadePhysicsCallback} processCallback - [description]
16761676
* @param {object} callbackContext - [description]
16771677
* @param {boolean} overlapOnly - [description]
16781678
*

src/physics/arcade/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
var CONST = require('./const');
88
var Extend = require('../../utils/object/Extend');
99

10+
/**
11+
* @callback ArcadePhysicsCallback
12+
*
13+
* @param {Phaser.GameObjects.GameObject} object1 - [description]
14+
* @param {Phaser.GameObjects.GameObject} object2 - [description]
15+
*/
16+
1017
/**
1118
* @namespace Phaser.Physics.Arcade
1219
*/
@@ -23,7 +30,7 @@ var Arcade = {
2330
StaticBody: require('./StaticBody'),
2431
StaticGroup: require('./StaticPhysicsGroup'),
2532
World: require('./World')
26-
33+
2734
};
2835

2936
// Merge in the consts

src/physics/impact/Body.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ var GetVelocity = require('./GetVelocity');
1010
var TYPE = require('./TYPE');
1111
var UpdateMotion = require('./UpdateMotion');
1212

13+
/**
14+
* @callback BodyUpdateCallback
15+
*
16+
* @param {Phaser.Physics.Impact.Body} body - [description]
17+
*/
18+
1319
/**
1420
* @classdesc
1521
* An Impact.js compatible physics body.
@@ -289,7 +295,7 @@ var Body = new Class({
289295
* [description]
290296
*
291297
* @name Phaser.Physics.Impact.Body#updateCallback
292-
* @type {function}
298+
* @type {?BodyUpdateCallback}
293299
* @since 3.0.0
294300
*/
295301
this.updateCallback;

0 commit comments

Comments
 (0)