phaser/src/physics/matter-js/components/Friction.js

85 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2023-01-02 17:36:27 +00:00
* @copyright 2013-2023 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-12-03 15:16:23 +00:00
* Contains methods for changing the friction of a Game Object's Matter Body. Should be used a mixin, not called directly.
*
* @namespace Phaser.Physics.Matter.Components.Friction
* @since 3.0.0
*/
var Friction = {
/**
2018-12-03 15:16:23 +00:00
* Sets new friction values for this Game Object's Matter Body.
*
* @method Phaser.Physics.Matter.Components.Friction#setFriction
* @since 3.0.0
*
2018-12-03 15:16:23 +00:00
* @param {number} value - The new friction of the body, between 0 and 1, where 0 allows the Body to slide indefinitely, while 1 allows it to stop almost immediately after a force is applied.
* @param {number} [air] - If provided, the new air resistance of the Body. The higher the value, the faster the Body will slow as it moves through space. 0 means the body has no air resistance.
* @param {number} [fstatic] - If provided, the new static friction of the Body. The higher the value (e.g. 10), the more force it will take to initially get the Body moving when it is nearly stationary. 0 means the body will never "stick" when it is nearly stationary.
*
2022-11-03 16:03:51 +00:00
* @return {this} This Game Object instance.
*/
2017-12-12 17:02:53 +00:00
setFriction: function (value, air, fstatic)
{
this.body.friction = value;
2017-11-27 03:44:31 +00:00
if (air !== undefined)
{
this.body.frictionAir = air;
}
2017-12-12 17:02:53 +00:00
if (fstatic !== undefined)
2017-11-27 03:44:31 +00:00
{
2017-12-12 17:02:53 +00:00
this.body.frictionStatic = fstatic;
2017-11-27 03:44:31 +00:00
}
return this;
},
/**
2020-01-09 13:17:43 +00:00
* Sets a new air resistance for this Game Object's Matter Body.
* A value of 0 means the Body will never slow as it moves through space.
* The higher the value, the faster a Body slows when moving through space.
*
* @method Phaser.Physics.Matter.Components.Friction#setFrictionAir
* @since 3.0.0
*
2018-12-03 15:16:23 +00:00
* @param {number} value - The new air resistance for the Body.
*
2022-11-03 16:03:51 +00:00
* @return {this} This Game Object instance.
*/
setFrictionAir: function (value)
{
this.body.frictionAir = value;
return this;
},
/**
2020-01-09 13:17:43 +00:00
* Sets a new static friction for this Game Object's Matter Body.
* A value of 0 means the Body will never "stick" when it is nearly stationary.
* The higher the value (e.g. 10), the more force it will take to initially get the Body moving when it is nearly stationary.
*
* @method Phaser.Physics.Matter.Components.Friction#setFrictionStatic
* @since 3.0.0
*
2018-12-03 15:16:23 +00:00
* @param {number} value - The new static friction for the Body.
*
2022-11-03 16:03:51 +00:00
* @return {this} This Game Object instance.
*/
setFrictionStatic: function (value)
{
this.body.frictionStatic = value;
return this;
}
};
module.exports = Friction;