JAVASCRIPT   15

Friction.js

Guest on 31st May 2021 02:37:20 AM

  1. /**
  2.  * @author       Richard Davey <rich@photonstorm.com>
  3.  * @copyright    2020 Photon Storm Ltd.
  4.  * @license      {@link https://opensource.org/licenses/MIT|MIT License}
  5.  */
  6.  
  7. /**
  8.  * Contains methods for changing the friction of a Game Object's Matter Body. Should be used a mixin, not called directly.
  9.  *
  10.  * @namespace Phaser.Physics.Matter.Components.Friction
  11.  * @since 3.0.0
  12.  */
  13. var Friction = {
  14.  
  15.     /**
  16.      * Sets new friction values for this Game Object's Matter Body.
  17.      *
  18.      * @method Phaser.Physics.Matter.Components.Friction#setFriction
  19.      * @since 3.0.0
  20.      *
  21.      * @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.
  22.      * @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.
  23.      * @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.
  24.      *
  25.      * @return {Phaser.GameObjects.GameObject} This Game Object.
  26.      */
  27.     setFriction: function (value, air, fstatic)
  28.     {
  29.         this.body.friction = value;
  30.  
  31.         if (air !== undefined)
  32.         {
  33.             this.body.frictionAir = air;
  34.         }
  35.  
  36.         if (fstatic !== undefined)
  37.         {
  38.             this.body.frictionStatic = fstatic;
  39.         }
  40.  
  41.         return this;
  42.     },
  43.  
  44.     /**
  45.      * Sets a new air resistance for this Game Object's Matter Body.
  46.      * A value of 0 means the Body will never slow as it moves through space.
  47.      * The higher the value, the faster a Body slows when moving through space.
  48.      *
  49.      * @method Phaser.Physics.Matter.Components.Friction#setFrictionAir
  50.      * @since 3.0.0
  51.      *
  52.      * @param {number} value - The new air resistance for the Body.
  53.      *
  54.      * @return {Phaser.GameObjects.GameObject} This Game Object.
  55.      */
  56.     setFrictionAir: function (value)
  57.     {
  58.         this.body.frictionAir = value;
  59.  
  60.         return this;
  61.     },
  62.  
  63.     /**
  64.      * Sets a new static friction for this Game Object's Matter Body.
  65.      * A value of 0 means the Body will never "stick" when it is nearly stationary.
  66.      * The higher the value (e.g. 10), the more force it will take to initially get the Body moving when it is nearly stationary.
  67.      *
  68.      * @method Phaser.Physics.Matter.Components.Friction#setFrictionStatic
  69.      * @since 3.0.0
  70.      *
  71.      * @param {number} value - The new static friction for the Body.
  72.      *
  73.      * @return {Phaser.GameObjects.GameObject} This Game Object.
  74.      */
  75.     setFrictionStatic: function (value)
  76.     {
  77.         this.body.frictionStatic = value;
  78.  
  79.         return this;
  80.     }
  81.  
  82. };
  83.  
  84. module.exports = Friction;

Raw Paste


Login or Register to edit or fork this paste. It's free.