/
Velocity.js
93 lines (82 loc) · 2.4 KB
/
Velocity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Provides methods for modifying the velocity of an Arcade Physics body.
*
* Should be applied as a mixin and not used directly.
*
* @namespace Phaser.Physics.Arcade.Components.Velocity
* @since 3.0.0
*/
var Velocity = {
/**
* Sets the velocity of the Body.
*
* @method Phaser.Physics.Arcade.Components.Velocity#setVelocity
* @since 3.0.0
*
* @param {number} x - The horizontal velocity of the body. Positive values move the body to the right, while negative values move it to the left.
* @param {number} [y=x] - The vertical velocity of the body. Positive values move the body down, while negative values move it up.
*
* @return {this} This Game Object.
*/
setVelocity: function (x, y)
{
this.body.setVelocity(x, y);
return this;
},
/**
* Sets the horizontal component of the body's velocity.
*
* Positive values move the body to the right, while negative values move it to the left.
*
* @method Phaser.Physics.Arcade.Components.Velocity#setVelocityX
* @since 3.0.0
*
* @param {number} x - The new horizontal velocity.
*
* @return {this} This Game Object.
*/
setVelocityX: function (x)
{
this.body.setVelocityX(x);
return this;
},
/**
* Sets the vertical component of the body's velocity.
*
* Positive values move the body down, while negative values move it up.
*
* @method Phaser.Physics.Arcade.Components.Velocity#setVelocityY
* @since 3.0.0
*
* @param {number} y - The new vertical velocity of the body.
*
* @return {this} This Game Object.
*/
setVelocityY: function (y)
{
this.body.setVelocityY(y);
return this;
},
/**
* Sets the maximum velocity of the body.
*
* @method Phaser.Physics.Arcade.Components.Velocity#setMaxVelocity
* @since 3.0.0
*
* @param {number} x - The new maximum horizontal velocity.
* @param {number} [y=x] - The new maximum vertical velocity.
*
* @return {this} This Game Object.
*/
setMaxVelocity: function (x, y)
{
this.body.maxVelocity.set(x, y);
return this;
}
};
module.exports = Velocity;