phaser/src/physics/matter-js/MatterImage.js

132 lines
4.4 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-02-12 16:01:20 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../../utils/Class');
var Components = require('./components');
var GameObject = require('../../gameobjects/GameObject');
var GetFastValue = require('../../utils/object/GetFastValue');
var Image = require('../../gameobjects/image/Image');
2018-02-12 13:14:50 +00:00
var Pipeline = require('../../gameobjects/components/Pipeline');
var Vector2 = require('../../math/Vector2');
2018-02-12 13:14:50 +00:00
/**
* @classdesc
* A Matter Physics Image Game Object.
*
* An Image is a light-weight Game Object useful for the display of static images in your game,
* such as logos, backgrounds, scenery or other non-animated elements. Images can have input
* events and physics bodies, or be tweened, tinted or scrolled. The main difference between an
* Image and a Sprite is that you cannot animate an Image as they do not have the Animation component.
*
2018-03-21 14:41:45 +00:00
* @class Image
2018-02-12 13:14:50 +00:00
* @extends Phaser.GameObjects.Image
2018-10-10 09:49:13 +00:00
* @memberof Phaser.Physics.Matter
2018-02-12 13:14:50 +00:00
* @constructor
* @since 3.0.0
*
* @extends Phaser.Physics.Matter.Components.Bounce
* @extends Phaser.Physics.Matter.Components.Collision
* @extends Phaser.Physics.Matter.Components.Force
* @extends Phaser.Physics.Matter.Components.Friction
* @extends Phaser.Physics.Matter.Components.Gravity
* @extends Phaser.Physics.Matter.Components.Mass
* @extends Phaser.Physics.Matter.Components.Sensor
* @extends Phaser.Physics.Matter.Components.SetBody
* @extends Phaser.Physics.Matter.Components.Sleep
* @extends Phaser.Physics.Matter.Components.Static
* @extends Phaser.Physics.Matter.Components.Transform
* @extends Phaser.Physics.Matter.Components.Velocity
* @extends Phaser.GameObjects.Components.Alpha
* @extends Phaser.GameObjects.Components.BlendMode
* @extends Phaser.GameObjects.Components.Depth
* @extends Phaser.GameObjects.Components.Flip
* @extends Phaser.GameObjects.Components.GetBounds
* @extends Phaser.GameObjects.Components.Origin
* @extends Phaser.GameObjects.Components.Pipeline
* @extends Phaser.GameObjects.Components.ScaleMode
* @extends Phaser.GameObjects.Components.ScrollFactor
* @extends Phaser.GameObjects.Components.Size
* @extends Phaser.GameObjects.Components.Texture
* @extends Phaser.GameObjects.Components.Tint
* @extends Phaser.GameObjects.Components.Transform
* @extends Phaser.GameObjects.Components.Visible
*
* @param {Phaser.Physics.Matter.World} world - [description]
* @param {number} x - The horizontal position of this Game Object in the world.
* @param {number} y - The vertical position of this Game Object in the world.
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
2018-03-28 13:11:46 +00:00
* @param {object} [options={}] - Matter.js configuration object.
2018-02-12 13:14:50 +00:00
*/
var MatterImage = new Class({
Extends: Image,
Mixins: [
Components.Bounce,
2017-11-22 02:25:06 +00:00
Components.Collision,
Components.Force,
Components.Friction,
2017-11-22 17:11:09 +00:00
Components.Gravity,
Components.Mass,
Components.Sensor,
Components.SetBody,
Components.Sleep,
Components.Static,
Components.Transform,
2018-01-30 19:16:00 +00:00
Components.Velocity,
Pipeline
],
initialize:
function MatterImage (world, x, y, texture, frame, options)
{
GameObject.call(this, world.scene, 'Image');
this.setTexture(texture, frame);
this.setSizeToFrame();
this.setOrigin();
2018-03-21 14:41:45 +00:00
/**
* [description]
*
* @name Phaser.Physics.Matter.Image#world
* @type {Phaser.Physics.Matter.World}
* @since 3.0.0
*/
this.world = world;
2018-03-21 14:41:45 +00:00
/**
* [description]
*
* @name Phaser.Physics.Matter.Image#_tempVec2
* @type {Phaser.Math.Vector2}
* @private
* @since 3.0.0
*/
this._tempVec2 = new Vector2(x, y);
var shape = GetFastValue(options, 'shape', null);
if (shape)
{
this.setBody(shape, options);
}
else
{
2018-04-11 15:58:25 +00:00
this.setRectangle(this.width, this.height, options);
}
this.setPosition(x, y);
2018-01-30 19:16:00 +00:00
this.initPipeline('TextureTintPipeline');
}
});
module.exports = MatterImage;