|
| 1 | +/** |
| 2 | + * @author Richard Davey <rich@photonstorm.com> |
| 3 | + * @copyright 2018 Photon Storm Ltd. |
| 4 | + * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
| 5 | + */ |
| 6 | + |
| 7 | +var Bodies = require('./lib/factory/Bodies'); |
| 8 | +var Class = require('../../utils/Class'); |
| 9 | +var Components = require('./components'); |
| 10 | +var GetFastValue = require('../../utils/object/GetFastValue'); |
| 11 | +var Vector2 = require('../../math/Vector2'); |
| 12 | + |
| 13 | +/** |
| 14 | + * @classdesc |
| 15 | + * A Matter Physics Body applied to a Game Object. |
| 16 | + * |
| 17 | + * @class MatterGameObject |
| 18 | + * @memberOf Phaser.Physics.Matter |
| 19 | + * @constructor |
| 20 | + * @since 3.3.0 |
| 21 | + * |
| 22 | + * @extends Phaser.Physics.Matter.Components.Bounce |
| 23 | + * @extends Phaser.Physics.Matter.Components.Collision |
| 24 | + * @extends Phaser.Physics.Matter.Components.Force |
| 25 | + * @extends Phaser.Physics.Matter.Components.Friction |
| 26 | + * @extends Phaser.Physics.Matter.Components.Gravity |
| 27 | + * @extends Phaser.Physics.Matter.Components.Mass |
| 28 | + * @extends Phaser.Physics.Matter.Components.Sensor |
| 29 | + * @extends Phaser.Physics.Matter.Components.SetBody |
| 30 | + * @extends Phaser.Physics.Matter.Components.Sleep |
| 31 | + * @extends Phaser.Physics.Matter.Components.Static |
| 32 | + * @extends Phaser.Physics.Matter.Components.Transform |
| 33 | + * @extends Phaser.Physics.Matter.Components.Velocity |
| 34 | + * |
| 35 | + * @param {Phaser.Physics.Matter.World} world - [description] |
| 36 | + * @param {Phaser.GameObjects.GameObject} gameObject - [description] |
| 37 | + * @param {object} options - [description] |
| 38 | + */ |
| 39 | +var MatterGameObject = new Class({ |
| 40 | + |
| 41 | + Mixins: [ |
| 42 | + Components.Bounce, |
| 43 | + Components.Collision, |
| 44 | + Components.Force, |
| 45 | + Components.Friction, |
| 46 | + Components.Gravity, |
| 47 | + Components.Mass, |
| 48 | + Components.Sensor, |
| 49 | + Components.SetBody, |
| 50 | + Components.Sleep, |
| 51 | + Components.Static, |
| 52 | + Components.Transform, |
| 53 | + Components.Velocity |
| 54 | + ], |
| 55 | + |
| 56 | + initialize: |
| 57 | + |
| 58 | + function MatterGameObject (world, gameObject, options) |
| 59 | + { |
| 60 | + this.gameObject = gameObject; |
| 61 | + |
| 62 | + this.world = world; |
| 63 | + |
| 64 | + this._tempVec2 = new Vector2(x, y); |
| 65 | + |
| 66 | + var shape = GetFastValue(options, 'shape', null); |
| 67 | + |
| 68 | + if (!shape) |
| 69 | + { |
| 70 | + this.body = Bodies.rectangle(gameObject.x, gameObject.y, gameObject.width, gameObject.height, options); |
| 71 | + |
| 72 | + this.body.gameObject = this.gameObject; |
| 73 | + |
| 74 | + if (GetFastValue(options, 'addToWorld', true)) |
| 75 | + { |
| 76 | + world.add(this.body); |
| 77 | + } |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + this.setBody(shape, options); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | +}); |
| 86 | + |
| 87 | +module.exports = MatterGameObject; |
0 commit comments