Added Impact Events.

This commit is contained in:
Richard Davey 2019-01-17 14:54:38 +00:00
parent 5494f6ac79
commit d41286bd4f
7 changed files with 79 additions and 4 deletions

View file

@ -5,6 +5,7 @@
*/ */
var COLLIDES = require('./COLLIDES'); var COLLIDES = require('./COLLIDES');
var Events = require('./events');
var SeperateX = require('./SeperateX'); var SeperateX = require('./SeperateX');
var SeperateY = require('./SeperateY'); var SeperateY = require('./SeperateY');
@ -12,6 +13,7 @@ var SeperateY = require('./SeperateY');
* Impact Physics Solver * Impact Physics Solver
* *
* @function Phaser.Physics.Impact.Solver * @function Phaser.Physics.Impact.Solver
* @fires Phaser.Physics.Impact.Events#COLLIDE
* @since 3.0.0 * @since 3.0.0
* *
* @param {Phaser.Physics.Impact.World} world - The Impact simulation to run the solver in. * @param {Phaser.Physics.Impact.World} world - The Impact simulation to run the solver in.
@ -45,7 +47,7 @@ var Solver = function (world, bodyA, bodyB)
bodyA.collideWith(bodyB, 'y'); bodyA.collideWith(bodyB, 'y');
bodyB.collideWith(bodyA, 'y'); bodyB.collideWith(bodyA, 'y');
world.emit('collide', bodyA, bodyB, 'y'); world.emit(Events.COLLIDE, bodyA, bodyB, 'y');
} }
else if (bodyA.last.y + bodyA.size.y > bodyB.last.y && bodyA.last.y < bodyB.last.y + bodyB.size.y) else if (bodyA.last.y + bodyA.size.y > bodyB.last.y && bodyA.last.y < bodyB.last.y + bodyB.size.y)
{ {
@ -61,7 +63,7 @@ var Solver = function (world, bodyA, bodyB)
bodyA.collideWith(bodyB, 'x'); bodyA.collideWith(bodyB, 'x');
bodyB.collideWith(bodyA, 'x'); bodyB.collideWith(bodyA, 'x');
world.emit('collide', bodyA, bodyB, 'x'); world.emit(Events.COLLIDE, bodyA, bodyB, 'x');
} }
}; };

View file

@ -9,6 +9,7 @@ var Class = require('../../utils/Class');
var COLLIDES = require('./COLLIDES'); var COLLIDES = require('./COLLIDES');
var CollisionMap = require('./CollisionMap'); var CollisionMap = require('./CollisionMap');
var EventEmitter = require('eventemitter3'); var EventEmitter = require('eventemitter3');
var Events = require('./events');
var GetFastValue = require('../../utils/object/GetFastValue'); var GetFastValue = require('../../utils/object/GetFastValue');
var HasValue = require('../../utils/object/HasValue'); var HasValue = require('../../utils/object/HasValue');
var Set = require('../../structs/Set'); var Set = require('../../structs/Set');
@ -556,6 +557,7 @@ var World = new Class({
* [description] * [description]
* *
* @method Phaser.Physics.Impact.World#pause * @method Phaser.Physics.Impact.World#pause
* @fires Phaser.Physics.Impact.Events#PAUSE
* @since 3.0.0 * @since 3.0.0
* *
* @return {Phaser.Physics.Impact.World} This World object. * @return {Phaser.Physics.Impact.World} This World object.
@ -564,7 +566,7 @@ var World = new Class({
{ {
this.enabled = false; this.enabled = false;
this.emit('pause'); this.emit(Events.PAUSE);
return this; return this;
}, },
@ -573,6 +575,7 @@ var World = new Class({
* [description] * [description]
* *
* @method Phaser.Physics.Impact.World#resume * @method Phaser.Physics.Impact.World#resume
* @fires Phaser.Physics.Impact.Events#RESUME
* @since 3.0.0 * @since 3.0.0
* *
* @return {Phaser.Physics.Impact.World} This World object. * @return {Phaser.Physics.Impact.World} This World object.
@ -581,7 +584,7 @@ var World = new Class({
{ {
this.enabled = true; this.enabled = true;
this.emit('resume'); this.emit(Events.RESUME);
return this; return this;
}, },

View file

@ -0,0 +1,20 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Impact Physics World Collide Event.
*
* This event is dispatched by an Impact Physics World instance if two bodies collide.
*
* Listen to it from a Scene using: `this.impact.world.on('collide', listener)`.
*
* @event Phaser.Physics.Impact.Events#COLLIDE
*
* @param {Phaser.Physics.Impact.Body} bodyA - The first body involved in the collision.
* @param {Phaser.Physics.Impact.Body} bodyB - The second body involved in the collision.
* @param {string} axis - The collision axis. Either `x` or `y`.
*/
module.exports = 'collide';

View file

@ -0,0 +1,16 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Impact Physics World Pause Event.
*
* This event is dispatched by an Impact Physics World instance when it is paused.
*
* Listen to it from a Scene using: `this.impact.world.on('pause', listener)`.
*
* @event Phaser.Physics.Impact.Events#PAUSE
*/
module.exports = 'pause';

View file

@ -0,0 +1,16 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Impact Physics World Resume Event.
*
* This event is dispatched by an Impact Physics World instance when it resumes from a paused state.
*
* Listen to it from a Scene using: `this.impact.world.on('resume', listener)`.
*
* @event Phaser.Physics.Impact.Events#RESUME
*/
module.exports = 'resume';

View file

@ -0,0 +1,17 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* @namespace Phaser.Physics.Impact.Events
*/
module.exports = {
COLLIDE: require('./COLLIDE_EVENT'),
PAUSE: require('./PAUSE_EVENT'),
RESUME: require('./RESUME_EVENT')
};

View file

@ -22,6 +22,7 @@
module.exports = { module.exports = {
Body: require('./Body'), Body: require('./Body'),
Events: require('./events'),
COLLIDES: require('./COLLIDES'), COLLIDES: require('./COLLIDES'),
CollisionMap: require('./CollisionMap'), CollisionMap: require('./CollisionMap'),
Factory: require('./Factory'), Factory: require('./Factory'),