phaser
Version:
A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.
68 lines (57 loc) • 1.75 kB
JavaScript
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../../../utils/Class');
var Vector2 = require('../../../math/Vector2');
/**
* @classdesc
* A zone that places particles randomly within a shapes area.
*
* @class RandomZone
* @memberof Phaser.GameObjects.Particles.Zones
* @constructor
* @since 3.0.0
*
* @param {Phaser.Types.GameObjects.Particles.RandomZoneSource} source - An object instance with a `getRandomPoint(point)` method.
*/
var RandomZone = new Class({
initialize:
function RandomZone (source)
{
/**
* An object instance with a `getRandomPoint(point)` method.
*
* @name Phaser.GameObjects.Particles.Zones.RandomZone#source
* @type {Phaser.Types.GameObjects.Particles.RandomZoneSource}
* @since 3.0.0
*/
this.source = source;
/**
* Internal calculation vector.
*
* @name Phaser.GameObjects.Particles.Zones.RandomZone#_tempVec
* @type {Phaser.Math.Vector2}
* @private
* @since 3.0.0
*/
this._tempVec = new Vector2();
},
/**
* Get the next point in the Zone and set its coordinates on the given Particle.
*
* @method Phaser.GameObjects.Particles.Zones.RandomZone#getPoint
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.Particle} particle - The Particle.
*/
getPoint: function (particle)
{
var vec = this._tempVec;
this.source.getRandomPoint(vec);
particle.x = vec.x;
particle.y = vec.y;
}
});
module.exports = RandomZone;