JAVASCRIPT   8

Sensor.js

Guest on 31st May 2021 02:33:14 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.  * Enables a Matter-enabled Game Object to be a sensor. Should be used as a mixin and not directly.
  9.  *
  10.  * @namespace Phaser.Physics.Matter.Components.Sensor
  11.  * @since 3.0.0
  12.  */
  13. var Sensor = {
  14.  
  15.     /**
  16.      * Set the body belonging to this Game Object to be a sensor.
  17.      * Sensors trigger collision events, but don't react with colliding body physically.
  18.      *
  19.      * @method Phaser.Physics.Matter.Components.Sensor#setSensor
  20.      * @since 3.0.0
  21.      *
  22.      * @param {boolean} value - `true` to set the body as a sensor, or `false` to disable it.
  23.      *
  24.      * @return {Phaser.GameObjects.GameObject} This Game Object.
  25.      */
  26.     setSensor: function (value)
  27.     {
  28.         this.body.isSensor = value;
  29.  
  30.         return this;
  31.     },
  32.  
  33.     /**
  34.      * Is the body belonging to this Game Object a sensor or not?
  35.      *
  36.      * @method Phaser.Physics.Matter.Components.Sensor#isSensor
  37.      * @since 3.0.0
  38.      *
  39.      * @return {boolean} `true` if the body is a sensor, otherwise `false`.
  40.      */
  41.     isSensor: function ()
  42.     {
  43.         return this.body.isSensor;
  44.     }
  45.  
  46. };
  47.  
  48. module.exports = Sensor;

Raw Paste


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