phaser/plugins/impact/components/Velocity.js

95 lines
2.2 KiB
JavaScript
Raw Normal View History

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-09-28 11:19:21 +00:00
* The Impact Velocity component.
* Should be applied as a mixin.
*
* @namespace Phaser.Physics.Impact.Components.Velocity
* @since 3.0.0
*/
2017-08-15 22:36:00 +00:00
var Velocity = {
/**
2018-09-28 11:19:21 +00:00
* Sets the horizontal velocity of the physics body.
*
* @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-09-28 11:19:21 +00:00
* @return {this} This Game Object.
*/
2017-08-15 22:36:00 +00:00
setVelocityX: function (x)
{
this.vel.x = x;
return this;
},
/**
2018-09-28 11:19:21 +00:00
* Sets the vertical velocity of the physics body.
*
* @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-09-28 11:19:21 +00:00
* @return {this} This Game Object.
*/
2017-08-15 22:36:00 +00:00
setVelocityY: function (y)
{
this.vel.y = y;
return this;
},
/**
2018-09-28 11:19:21 +00:00
* Sets the horizontal and vertical velocities of the physics body.
*
* @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-09-28 11:19:21 +00:00
* @return {this} This Game Object.
*/
2017-08-15 22:36:00 +00:00
setVelocity: function (x, y)
{
if (y === undefined) { y = x; }
2017-08-15 22:36:00 +00:00
this.vel.x = x;
this.vel.y = y;
return this;
},
/**
2018-09-28 11:19:21 +00:00
* Sets the maximum velocity this body can travel at.
*
* @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-09-28 11:19:21 +00:00
* @return {this} This Game Object.
*/
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;