2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-09 01:40:41 +00:00
|
|
|
/**
|
2018-09-28 11:19:21 +00:00
|
|
|
* The Impact Velocity component.
|
|
|
|
* Should be applied as a mixin.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
2019-02-12 15:01:54 +00:00
|
|
|
* @namespace Phaser.Physics.Impact.Components.Velocity
|
2018-02-09 01:40:41 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-15 22:36:00 +00:00
|
|
|
var Velocity = {
|
|
|
|
|
2018-02-09 01:40:41 +00:00
|
|
|
/**
|
2018-09-28 11:19:21 +00:00
|
|
|
* Sets the horizontal velocity of the physics body.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Components.Velocity#setVelocityX
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @param {number} x - The horizontal velocity value.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @return {this} This Game Object.
|
2018-02-09 01:40:41 +00:00
|
|
|
*/
|
2017-08-15 22:36:00 +00:00
|
|
|
setVelocityX: function (x)
|
|
|
|
{
|
|
|
|
this.vel.x = x;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 01:40:41 +00:00
|
|
|
/**
|
2018-09-28 11:19:21 +00:00
|
|
|
* Sets the vertical velocity of the physics body.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Components.Velocity#setVelocityY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @param {number} y - The vertical velocity value.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @return {this} This Game Object.
|
2018-02-09 01:40:41 +00:00
|
|
|
*/
|
2017-08-15 22:36:00 +00:00
|
|
|
setVelocityY: function (y)
|
|
|
|
{
|
|
|
|
this.vel.y = y;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 01:40:41 +00:00
|
|
|
/**
|
2018-09-28 11:19:21 +00:00
|
|
|
* Sets the horizontal and vertical velocities of the physics body.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Components.Velocity#setVelocity
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @param {number} x - The horizontal velocity value.
|
|
|
|
* @param {number} [y=x] - The vertical velocity value. If not given, defaults to the horizontal value.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @return {this} This Game Object.
|
2018-02-09 01:40:41 +00:00
|
|
|
*/
|
2017-08-15 22:36:00 +00:00
|
|
|
setVelocity: function (x, y)
|
|
|
|
{
|
2018-01-25 14:45:40 +00:00
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
2017-08-15 22:36:00 +00:00
|
|
|
this.vel.x = x;
|
|
|
|
this.vel.y = y;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 01:40:41 +00:00
|
|
|
/**
|
2018-09-28 11:19:21 +00:00
|
|
|
* Sets the maximum velocity this body can travel at.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Components.Velocity#setMaxVelocity
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @param {number} x - The maximum allowed horizontal velocity.
|
|
|
|
* @param {number} [y=x] - The maximum allowed vertical velocity. If not given, defaults to the horizontal value.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @return {this} This Game Object.
|
2018-02-09 01:40:41 +00:00
|
|
|
*/
|
2017-08-15 22:36:00 +00:00
|
|
|
setMaxVelocity: function (x, y)
|
|
|
|
{
|
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
|
|
|
this.maxVel.x = x;
|
|
|
|
this.maxVel.y = y;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Velocity;
|