Skip to content

Commit 1f9243f

Browse files
authored
Merge pull request phaserjs#5322 from samme/feature/setMaxVelocity
Set maxVelocity in PhysicsGroupConfig
2 parents 0680ff1 + 426c963 commit 1f9243f

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,40 @@ var Body = new Class({
18191819
return this;
18201820
},
18211821

1822+
/**
1823+
* Sets the Body's maximum horizontal velocity.
1824+
*
1825+
* @method Phaser.Physics.Arcade.Body#setMaxVelocityX
1826+
* @since 3.50.0
1827+
*
1828+
* @param {number} value - The maximum horizontal velocity, in pixels per second.
1829+
*
1830+
* @return {Phaser.Physics.Arcade.Body} This Body object.
1831+
*/
1832+
setMaxVelocityX: function (value)
1833+
{
1834+
this.maxVelocity.x = value;
1835+
1836+
return this;
1837+
},
1838+
1839+
/**
1840+
* Sets the Body's maximum vertical velocity.
1841+
*
1842+
* @method Phaser.Physics.Arcade.Body#setMaxVelocityY
1843+
* @since 3.50.0
1844+
*
1845+
* @param {number} value - The maximum vertical velocity, in pixels per second.
1846+
*
1847+
* @return {Phaser.Physics.Arcade.Body} This Body object.
1848+
*/
1849+
setMaxVelocityY: function (value)
1850+
{
1851+
this.maxVelocity.y = value;
1852+
1853+
return this;
1854+
},
1855+
18221856
/**
18231857
* Sets the maximum speed the Body can move.
18241858
*

src/physics/arcade/PhysicsGroup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ var PhysicsGroup = new Class({
145145
setGravityY: GetFastValue(config, 'gravityY', 0),
146146
setFrictionX: GetFastValue(config, 'frictionX', 0),
147147
setFrictionY: GetFastValue(config, 'frictionY', 0),
148+
setMaxVelocityX: GetFastValue(config, 'maxVelocityX', 10000),
149+
setMaxVelocityY: GetFastValue(config, 'maxVelocityY', 10000),
148150
setVelocityX: GetFastValue(config, 'velocityX', 0),
149151
setVelocityY: GetFastValue(config, 'velocityY', 0),
150152
setAngularVelocity: GetFastValue(config, 'angularVelocity', 0),

src/physics/arcade/typedefs/PhysicsGroupConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @property {number} [gravityY=0] - Sets {@link Phaser.Physics.Arcade.Body#gravity gravity.y}.
2020
* @property {number} [frictionX=0] - Sets {@link Phaser.Physics.Arcade.Body#friction friction.x}.
2121
* @property {number} [frictionY=0] - Sets {@link Phaser.Physics.Arcade.Body#friction friction.y}.
22+
* @property {number} [maxVelocityX=10000] - Sets {@link Phaser.Physics.Arcade.Body#maxVelocity maxVelocity.x}.
23+
* @property {number} [maxVelocityY=10000] - Sets {@link Phaser.Physics.Arcade.Body#maxVelocity maxVelocity.y}.
2224
* @property {number} [velocityX=0] - Sets {@link Phaser.Physics.Arcade.Body#velocity velocity.x}.
2325
* @property {number} [velocityY=0] - Sets {@link Phaser.Physics.Arcade.Body#velocity velocity.y}.
2426
* @property {number} [angularVelocity=0] - Sets {@link Phaser.Physics.Arcade.Body#angularVelocity}.

0 commit comments

Comments
 (0)