/
Velocity.js
95 lines (80 loc) · 2.47 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
94
95
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Body = require('../lib/body/Body');
/**
* Contains methods for changing the velocity of a Matter Body. Should be used as a mixin and not called directly.
*
* @namespace Phaser.Physics.Matter.Components.Velocity
* @since 3.0.0
*/
var Velocity = {
/**
* Sets the angular velocity of the body instantly.
* Position, angle, force etc. are unchanged.
*
* @method Phaser.Physics.Matter.Components.Velocity#setAngularVelocity
* @since 3.0.0
*
* @param {number} value - The angular velocity.
*
* @return {Phaser.GameObjects.GameObject} This Game Object.
*/
setAngularVelocity: function (value)
{
Body.setAngularVelocity(this.body, value);
return this;
},
/**
* Sets the horizontal velocity of the physics body.
*
* @method Phaser.Physics.Matter.Components.Velocity#setVelocityX
* @since 3.0.0
*
* @param {number} x - The horizontal velocity value.
*
* @return {Phaser.GameObjects.GameObject} This Game Object.
*/
setVelocityX: function (x)
{
this._tempVec2.set(x, this.body.velocity.y);
Body.setVelocity(this.body, this._tempVec2);
return this;
},
/**
* Sets vertical velocity of the physics body.
*
* @method Phaser.Physics.Matter.Components.Velocity#setVelocityY
* @since 3.0.0
*
* @param {number} y - The vertical velocity value.
*
* @return {Phaser.GameObjects.GameObject} This Game Object.
*/
setVelocityY: function (y)
{
this._tempVec2.set(this.body.velocity.x, y);
Body.setVelocity(this.body, this._tempVec2);
return this;
},
/**
* Sets both the horizontal and vertical velocity of the physics body.
*
* @method Phaser.Physics.Matter.Components.Velocity#setVelocity
* @since 3.0.0
*
* @param {number} x - The horizontal velocity value.
* @param {number} [y=x] - The vertical velocity value, it can be either positive or negative. If not given, it will be the same as the `x` value.
*
* @return {Phaser.GameObjects.GameObject} This Game Object.
*/
setVelocity: function (x, y)
{
this._tempVec2.set(x, y);
Body.setVelocity(this.body, this._tempVec2);
return this;
}
};
module.exports = Velocity;