Skip to content

Commit 43e76a7

Browse files
authored
Merge pull request phaserjs#4129 from samme/docs/events
Docs for input and physics events
2 parents f3a46f5 + 7ff8d51 commit 43e76a7

4 files changed

Lines changed: 239 additions & 17 deletions

File tree

src/gameobjects/GameObject.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,9 @@ var GameObject = new Class({
531531
* Game Object Pool instead of destroying it, as destroyed objects cannot be resurrected.
532532
*
533533
* @method Phaser.GameObjects.GameObject#destroy
534+
* @fires Phaser.GameObjects.GameObject#destroyEvent
534535
* @since 3.0.0
535-
*
536+
*
536537
* @param {boolean} [fromScene=false] - Is this Game Object being destroyed as the result of a Scene shutdown?
537538
*/
538539
destroy: function (fromScene)
@@ -607,3 +608,8 @@ var GameObject = new Class({
607608
GameObject.RENDER_MASK = 15;
608609

609610
module.exports = GameObject;
611+
612+
/**
613+
* The Game Object will be destroyed.
614+
* @event Phaser.GameObjects.GameObject#destroyEvent
615+
*/

src/input/InputPlugin.js

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,9 @@ var InputPlugin = new Class({
748748
*
749749
* @method Phaser.Input.InputPlugin#processDownEvents
750750
* @private
751+
* @fires Phaser.GameObjects.GameObject#pointerdownEvent
752+
* @fires Phaser.Input.InputPlugin#gameobjectdownEvent
753+
* @fires Phaser.Input.InputPlugin#pointerdownEvent
751754
* @since 3.0.0
752755
*
753756
* @param {Phaser.Input.Pointer} pointer - The Pointer being tested.
@@ -809,6 +812,20 @@ var InputPlugin = new Class({
809812
*
810813
* @method Phaser.Input.InputPlugin#processDragEvents
811814
* @private
815+
* @fires Phaser.GameObjects.GameObject#dragendEvent
816+
* @fires Phaser.GameObjects.GameObject#dragenterEvent
817+
* @fires Phaser.GameObjects.GameObject#dragEvent
818+
* @fires Phaser.GameObjects.GameObject#dragleaveEvent
819+
* @fires Phaser.GameObjects.GameObject#dragoverEvent
820+
* @fires Phaser.GameObjects.GameObject#dragstartEvent
821+
* @fires Phaser.GameObjects.GameObject#dropEvent
822+
* @fires Phaser.Input.InputPlugin#dragendEvent
823+
* @fires Phaser.Input.InputPlugin#dragenterEvent
824+
* @fires Phaser.Input.InputPlugin#dragEvent
825+
* @fires Phaser.Input.InputPlugin#dragleaveEvent
826+
* @fires Phaser.Input.InputPlugin#dragoverEvent
827+
* @fires Phaser.Input.InputPlugin#dragstartEvent
828+
* @fires Phaser.Input.InputPlugin#dropEvent
812829
* @since 3.0.0
813830
*
814831
* @param {Phaser.Input.Pointer} pointer - The Pointer to check against the Game Objects.
@@ -1077,6 +1094,8 @@ var InputPlugin = new Class({
10771094
*
10781095
* @method Phaser.Input.InputPlugin#processMoveEvents
10791096
* @private
1097+
* @fires Phaser.GameObjects.GameObject#pointermoveEvent
1098+
* @fires Phaser.Input.InputPlugin#gameobjectmoveEvent
10801099
* @since 3.0.0
10811100
*
10821101
* @param {Phaser.Input.Pointer} pointer - The pointer to check for events against.
@@ -1142,6 +1161,10 @@ var InputPlugin = new Class({
11421161
*
11431162
* @method Phaser.Input.InputPlugin#processOverOutEvents
11441163
* @private
1164+
* @fires Phaser.GameObjects.GameObject#pointeroutEvent
1165+
* @fires Phaser.GameObjects.GameObject#pointeroverEvent
1166+
* @fires Phaser.Input.InputPlugin#gameobjectoutEvent
1167+
* @fires Phaser.Input.InputPlugin#gameobjectoverEvent
11451168
* @since 3.0.0
11461169
*
11471170
* @param {Phaser.Input.Pointer} pointer - The pointer to check for events against.
@@ -1312,6 +1335,8 @@ var InputPlugin = new Class({
13121335
*
13131336
* @method Phaser.Input.InputPlugin#processUpEvents
13141337
* @private
1338+
* @fires Phaser.GameObjects.GameObject#pointerupEvent
1339+
* @fires Phaser.Input.InputPlugin#gameobjectupEvent
13151340
* @since 3.0.0
13161341
*
13171342
* @param {Phaser.Input.Pointer} pointer - The pointer to check for events against.
@@ -2493,3 +2518,161 @@ var InputPlugin = new Class({
24932518
PluginCache.register('InputPlugin', InputPlugin, 'input');
24942519

24952520
module.exports = InputPlugin;
2521+
2522+
/**
2523+
* A Pointer stopped dragging the Game Object.
2524+
* @event Phaser.GameObjects.GameObject#dragendEvent
2525+
* @param {Phaser.Input.Pointer} pointer - The Pointer that was dragging this Game Object.
2526+
* @param {number} dragX - The x coordinate where the Pointer is dragging the object, in world space.
2527+
* @param {number} dragY - The y coordinate where the Pointer is dragging the object, in world space.
2528+
* @param {boolean} dropped - True if the object was dropped within its drop target. (In that case, 'drop' was emitted before this.)
2529+
*
2530+
* The Game Object entered its drop target, while being dragged.
2531+
* @event Phaser.GameObjects.GameObject#dragenterEvent
2532+
* @param {Phaser.Input.Pointer} pointer - The pointer dragging this Game Object.
2533+
* @param {Phaser.GameObjects.GameObject} target - The Game Object's drop target.
2534+
*
2535+
* The Game Object is being dragged by a Pointer.
2536+
* @event Phaser.GameObjects.GameObject#dragEvent
2537+
* @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object.
2538+
* @param {number} dragX - The x coordinate where the Pointer is dragging the object, in world space.
2539+
* @param {number} dragY - The y coordinate where the Pointer is dragging the object, in world space.
2540+
*
2541+
* The Game Object left its drop target, while being dragged.
2542+
* @event Phaser.GameObjects.GameObject#dragleaveEvent
2543+
* @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object.
2544+
* @param {Phaser.GameObjects.GameObject} target - The Game Object's drop target.
2545+
*
2546+
* The Game Object is within its drop target, while being dragged.
2547+
* @event Phaser.GameObjects.GameObject#dragoverEvent
2548+
* @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object.
2549+
* @param {Phaser.GameObjects.GameObject} target - The Game Object's drop target.
2550+
*
2551+
* A Pointer began dragging the Game Object.
2552+
* @event Phaser.GameObjects.GameObject#dragstartEvent
2553+
* @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object.
2554+
* @param {number} dragX - The x coordinate where the Pointer is dragging the object, in world space.
2555+
* @param {number} dragY - The y coordinate where the Pointer is dragging the object, in world space.
2556+
*
2557+
* The Game Object was released on its drop target, after being dragged.
2558+
* @event Phaser.GameObjects.GameObject#dropEvent
2559+
* @param {Phaser.Input.Pointer} pointer - The Pointer dragging this Game Object.
2560+
* @param {Phaser.GameObjects.GameObject} target - The Game Object's drop target.
2561+
*
2562+
* A Pointer was pressed on the Game Object.
2563+
* @event Phaser.GameObjects.GameObject#pointerdownEvent
2564+
* @param {Phaser.Input.Pointer}
2565+
* @param {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
2566+
* @param {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
2567+
* @param {object} eventContainer
2568+
*
2569+
* A Pointer moved while over the Game Object.
2570+
* @event Phaser.GameObjects.GameObject#pointermoveEvent
2571+
* @param {Phaser.Input.Pointer}
2572+
* @param {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
2573+
* @param {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
2574+
* @param {object} eventContainer
2575+
*
2576+
* A Pointer left the Game Object, after being over it.
2577+
* @event Phaser.GameObjects.GameObject#pointeroutEvent
2578+
* @param {Phaser.Input.Pointer} - The Pointer.
2579+
* @param {object} eventContainer
2580+
*
2581+
* A Pointer entered the Game Object, after being outside it.
2582+
* @event Phaser.GameObjects.GameObject#pointeroverEvent
2583+
* @param {Phaser.Input.Pointer} - The Pointer.
2584+
* @param {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
2585+
* @param {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
2586+
* @param {object} eventContainer
2587+
*
2588+
* A Pointer was released while over the Game Object, after being pressed on the Game Object.
2589+
* @event Phaser.GameObjects.GameObject#pointerupEvent
2590+
* @param {Phaser.Input.Pointer} - The Pointer.
2591+
* @param {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
2592+
* @param {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
2593+
* @param {object} eventContainer
2594+
*/
2595+
2596+
/**
2597+
* A Game Object was released, after being dragged.
2598+
* @event Phaser.Input.InputPlugin#dragendEvent
2599+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2600+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2601+
* @param {boolean} dropped - True if the Game Object was dropped onto its drop target.
2602+
*
2603+
* A dragged Game Object entered it drop target.
2604+
* @event Phaser.Input.InputPlugin#dragenterEvent
2605+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2606+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2607+
* @param {Phaser.GameObjects.GameObject} target - The drop target.
2608+
*
2609+
* A Game Object is being dragged by a Pointer.
2610+
* @event Phaser.Input.InputPlugin#dragEvent
2611+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2612+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2613+
* @param {number} dragX - The x coordinate where the Pointer is dragging the object, in world space.
2614+
* @param {number} dragY - The y coordinate where the Pointer is dragging the object, in world space.
2615+
*
2616+
* A dragged Game Object left its drop target.
2617+
* @event Phaser.Input.InputPlugin#dragleaveEvent
2618+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2619+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2620+
* @param {?Phaser.GameObjects.GameObject} target - The drop target.
2621+
*
2622+
* A dragged Game Object is within its drop target.
2623+
* @event Phaser.Input.InputPlugin#dragoverEvent
2624+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2625+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2626+
* @param {?Phaser.GameObjects.GameObject} target - The drop target.
2627+
*
2628+
* A Pointer started dragging a Game Object.
2629+
* @event Phaser.Input.InputPlugin#dragstartEvent
2630+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2631+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2632+
*
2633+
* A Game Object was dropped within its drop target.
2634+
* @event Phaser.Input.InputPlugin#dropEvent
2635+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2636+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2637+
* @param {?Phaser.GameObjects.GameObject} target - The drop target.
2638+
*
2639+
* A Pointer was pressed while over a Game Object.
2640+
* @event Phaser.Input.InputPlugin#gameobjectdownEvent
2641+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2642+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2643+
* @param {object} eventContainer
2644+
*
2645+
* A Pointer moved while over a Game Object.
2646+
* @event Phaser.Input.InputPlugin#gameobjectmoveEvent
2647+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2648+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2649+
* @param {object} eventContainer
2650+
*
2651+
* A Pointer moved off of a Game Object, after being over it.
2652+
* @event Phaser.Input.InputPlugin#gameobjectoutEvent
2653+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2654+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2655+
* @param {object} eventContainer
2656+
*
2657+
* A Pointer moved onto a Game Object, after being off it.
2658+
* @event Phaser.Input.InputPlugin#gameobjectoverEvent
2659+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2660+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2661+
* @param {object} eventContainer
2662+
*
2663+
* A Pointer was released while over a Game Object, after being pressed on the Game Object.
2664+
* @event Phaser.Input.InputPlugin#gameobjectupEvent
2665+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2666+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object.
2667+
* @param {object} eventContainer
2668+
*
2669+
* A Pointer was pressed down.
2670+
* @event Phaser.Input.InputPlugin#pointerdownEvent
2671+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2672+
* @param {Phaser.GameObjects.GameObject[]} currentlyOver - All the Game Objects currently under the Pointer.
2673+
*
2674+
* A Pointer was released, after being pressed down.
2675+
* @event Phaser.Input.InputPlugin#pointerupEvent
2676+
* @param {Phaser.Input.Pointer} pointer - The Pointer.
2677+
* @param {Phaser.GameObjects.GameObject[]} currentlyOver - All the Game Objects currently under the Pointer.
2678+
*/

src/physics/arcade/Body.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ var Body = new Class({
401401
* @type {boolean}
402402
* @default false
403403
* @since 3.0.0
404-
* @see Phaser.Physics.Arcade.World#event:worldbounds
404+
* @see Phaser.Physics.Arcade.World#worldboundsEvent
405405
*/
406406
this.onWorldBounds = false;
407407

@@ -412,7 +412,7 @@ var Body = new Class({
412412
* @type {boolean}
413413
* @default false
414414
* @since 3.0.0
415-
* @see Phaser.Physics.Arcade.World#event:collide
415+
* @see Phaser.Physics.Arcade.World#collideEvent
416416
*/
417417
this.onCollide = false;
418418

@@ -423,7 +423,7 @@ var Body = new Class({
423423
* @type {boolean}
424424
* @default false
425425
* @since 3.0.0
426-
* @see Phaser.Physics.Arcade.World#event:overlap
426+
* @see Phaser.Physics.Arcade.World#overlapEvent
427427
*/
428428
this.onOverlap = false;
429429

src/physics/arcade/World.js

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,47 @@ var Vector2 = require('../../math/Vector2');
3232
var Wrap = require('../../math/Wrap');
3333

3434
/**
35-
* @event Phaser.Physics.Arcade.World#pause
35+
* The physics simulation paused.
36+
* @event Phaser.Physics.Arcade.World#pauseEvent
3637
*/
3738

3839
/**
39-
* @event Phaser.Physics.Arcade.World#resume
40+
* The physics simulation resumed (from a paused state).
41+
* @event Phaser.Physics.Arcade.World#resumeEvent
4042
*/
4143

4244
/**
43-
* @event Phaser.Physics.Arcade.World#collide
45+
* Two Game Objects collided.
46+
* This event is emitted only if at least one body has `onCollide` enabled.
47+
* @event Phaser.Physics.Arcade.World#collideEvent
4448
* @param {Phaser.GameObjects.GameObject} gameObject1
4549
* @param {Phaser.GameObjects.GameObject} gameObject2
4650
* @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body1
4751
* @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body2
52+
* @see Phaser.Physics.Arcade.Body#onCollide
4853
*/
4954

5055
/**
51-
* @event Phaser.Physics.Arcade.World#overlap
56+
* Two Game Objects overlapped.
57+
* This event is emitted only if at least one body has `onOverlap` enabled.
58+
* @event Phaser.Physics.Arcade.World#overlapEvent
5259
* @param {Phaser.GameObjects.GameObject} gameObject1
5360
* @param {Phaser.GameObjects.GameObject} gameObject2
5461
* @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body1
5562
* @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body2
63+
* @see Phaser.Physics.Arcade.Body#onOverlap
5664
*/
5765

5866
/**
59-
* @event Phaser.Physics.Arcade.World#worldbounds
67+
* A Body contacted the world boundary.
68+
* This event is emitted only if the body has `onWorldBounds` enabled.
69+
* @event Phaser.Physics.Arcade.World#worldboundsEvent
6070
* @param {Phaser.Physics.Arcade.Body} body
6171
* @param {boolean} up
6272
* @param {boolean} down
6373
* @param {boolean} left
6474
* @param {boolean} right
75+
* @see Phaser.Physics.Arcade.Body#onWorldBounds
6576
*/
6677

6778
/**
@@ -853,7 +864,7 @@ var World = new Class({
853864
* checks.
854865
*
855866
* @method Phaser.Physics.Arcade.World#pause
856-
* @fires Phaser.Physics.Arcade.World#pause
867+
* @fires Phaser.Physics.Arcade.World#pauseEvent
857868
* @since 3.0.0
858869
*
859870
* @return {Phaser.Physics.Arcade.World} This World object.
@@ -871,7 +882,7 @@ var World = new Class({
871882
* Resumes the simulation, if paused.
872883
*
873884
* @method Phaser.Physics.Arcade.World#resume
874-
* @fires Phaser.Physics.Arcade.World#resume
885+
* @fires Phaser.Physics.Arcade.World#resumeEvent
875886
* @since 3.0.0
876887
*
877888
* @return {Phaser.Physics.Arcade.World} This World object.
@@ -1361,8 +1372,8 @@ var World = new Class({
13611372
* Separates two Bodies.
13621373
*
13631374
* @method Phaser.Physics.Arcade.World#separate
1364-
* @fires Phaser.Physics.Arcade.World#collide
1365-
* @fires Phaser.Physics.Arcade.World#overlap
1375+
* @fires Phaser.Physics.Arcade.World#collideEvent
1376+
* @fires Phaser.Physics.Arcade.World#overlapEvent
13661377
* @since 3.0.0
13671378
*
13681379
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body to be separated.
@@ -1476,8 +1487,8 @@ var World = new Class({
14761487
* Separates two Bodies, when both are circular.
14771488
*
14781489
* @method Phaser.Physics.Arcade.World#separateCircle
1479-
* @fires Phaser.Physics.Arcade.World#collide
1480-
* @fires Phaser.Physics.Arcade.World#overlap
1490+
* @fires Phaser.Physics.Arcade.World#collideEvent
1491+
* @fires Phaser.Physics.Arcade.World#overlapEvent
14811492
* @since 3.0.0
14821493
*
14831494
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body to be separated.
@@ -2132,8 +2143,10 @@ var World = new Class({
21322143
* Please use Phaser.Physics.Arcade.World#collide instead.
21332144
*
21342145
* @method Phaser.Physics.Arcade.World#collideSpriteVsTilemapLayer
2135-
* @fires Phaser.Physics.Arcade.World#collide
2136-
* @fires Phaser.Physics.Arcade.World#overlap
2146+
* @fires Phaser.GameObjects.GameObject#collideEvent
2147+
* @fires Phaser.GameObjects.GameObject#overlapEvent
2148+
* @fires Phaser.Physics.Arcade.World#collideEvent
2149+
* @fires Phaser.Physics.Arcade.World#overlapEvent
21372150
* @since 3.0.0
21382151
*
21392152
* @param {Phaser.GameObjects.GameObject} sprite - The first object to check for collision.
@@ -2363,3 +2376,23 @@ var World = new Class({
23632376
});
23642377

23652378
module.exports = World;
2379+
2380+
/**
2381+
* A physics-enabled Game Object collided with a Tile.
2382+
* This event is emitted only if the Game Object's body has `onCollide` enabled.
2383+
* @event Phaser.GameObjects.GameObject#collideEvent
2384+
* @param {Phaser.GameObjects.GameObject} gameObject
2385+
* @param {Phaser.Tilemaps.Tile} tile
2386+
* @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body
2387+
* @see Phaser.Physics.Arcade.Body#onCollide
2388+
*/
2389+
2390+
/**
2391+
* A physics-enabled Game Object overlapped with a Tile.
2392+
* This event is emitted only if the Game Object's body has `onOverlap` enabled.
2393+
* @event Phaser.GameObjects.GameObject#overlapEvent
2394+
* @param {Phaser.GameObjects.GameObject} gameObject
2395+
* @param {Phaser.Tilemaps.Tile} tile
2396+
* @param {Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody} body
2397+
* @see Phaser.Physics.Arcade.Body#onOverlap
2398+
*/

0 commit comments

Comments
 (0)