2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 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
|
|
|
*/
|
|
|
|
|
2017-08-15 22:38:35 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-08-21 18:16:19 +00:00
|
|
|
var Components = require('./components');
|
2017-08-15 22:38:35 +00:00
|
|
|
var Sprite = require('../../gameobjects/sprite/Sprite');
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* An Impact Physics Sprite Game Object.
|
|
|
|
*
|
|
|
|
* A Sprite Game Object is used for the display of both static and animated images in your game.
|
|
|
|
* Sprites can have input events and physics bodies. They can also be tweened, tinted, scrolled
|
|
|
|
* and animated.
|
|
|
|
*
|
|
|
|
* The main difference between a Sprite and an Image Game Object is that you cannot animate Images.
|
|
|
|
* As such, Sprites take a fraction longer to process and have a larger API footprint due to the Animation
|
|
|
|
* Component. If you do not require animation then you can safely use Images to replace Sprites in all cases.
|
|
|
|
*
|
|
|
|
* @class ImpactSprite
|
|
|
|
* @extends Phaser.GameObjects.Sprite
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Physics.Impact
|
2018-02-09 16:04:43 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @extends Phaser.Physics.Impact.Components.Acceleration
|
|
|
|
* @extends Phaser.Physics.Impact.Components.BodyScale
|
|
|
|
* @extends Phaser.Physics.Impact.Components.BodyType
|
|
|
|
* @extends Phaser.Physics.Impact.Components.Bounce
|
|
|
|
* @extends Phaser.Physics.Impact.Components.CheckAgainst
|
|
|
|
* @extends Phaser.Physics.Impact.Components.Collides
|
|
|
|
* @extends Phaser.Physics.Impact.Components.Debug
|
|
|
|
* @extends Phaser.Physics.Impact.Components.Friction
|
|
|
|
* @extends Phaser.Physics.Impact.Components.Gravity
|
|
|
|
* @extends Phaser.Physics.Impact.Components.Offset
|
|
|
|
* @extends Phaser.Physics.Impact.Components.SetGameObject
|
|
|
|
* @extends Phaser.Physics.Impact.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.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.Impact.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.
|
2018-03-20 15:10:19 +00:00
|
|
|
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
|
2018-02-09 16:04:43 +00:00
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
var ImpactSprite = new Class({
|
|
|
|
|
|
|
|
Extends: Sprite,
|
|
|
|
|
|
|
|
Mixins: [
|
|
|
|
Components.Acceleration,
|
2017-08-17 05:00:38 +00:00
|
|
|
Components.BodyScale,
|
2017-08-15 22:38:35 +00:00
|
|
|
Components.BodyType,
|
|
|
|
Components.Bounce,
|
|
|
|
Components.CheckAgainst,
|
|
|
|
Components.Collides,
|
2017-08-16 18:31:59 +00:00
|
|
|
Components.Debug,
|
2017-08-17 02:48:39 +00:00
|
|
|
Components.Friction,
|
2017-08-15 23:30:12 +00:00
|
|
|
Components.Gravity,
|
2017-08-16 21:10:43 +00:00
|
|
|
Components.Offset,
|
2017-08-17 00:21:01 +00:00
|
|
|
Components.SetGameObject,
|
2017-08-15 22:38:35 +00:00
|
|
|
Components.Velocity
|
|
|
|
],
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function ImpactSprite (world, x, y, texture, frame)
|
|
|
|
{
|
|
|
|
Sprite.call(this, world.scene, x, y, texture, frame);
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactSprite#body
|
|
|
|
* @type {Phaser.Physics.Impact.Body}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-16 18:31:59 +00:00
|
|
|
this.body = world.create(x - this.frame.centerX, y - this.frame.centerY, this.width, this.height);
|
2017-08-15 22:38:35 +00:00
|
|
|
|
2017-08-17 01:32:08 +00:00
|
|
|
this.body.parent = this;
|
2017-08-15 22:38:35 +00:00
|
|
|
this.body.gameObject = this;
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactSprite#size
|
|
|
|
* @type {{x: number, y: number}}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-16 16:27:15 +00:00
|
|
|
this.size = this.body.size;
|
2018-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactSprite#offset
|
|
|
|
* @type {{x: number, y: number}}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-16 18:31:59 +00:00
|
|
|
this.offset = this.body.offset;
|
2018-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactSprite#vel
|
|
|
|
* @type {{x: number, y: number}}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
this.vel = this.body.vel;
|
2018-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactSprite#accel
|
|
|
|
* @type {{x: number, y: number}}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
this.accel = this.body.accel;
|
2018-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactSprite#friction
|
|
|
|
* @type {{x: number, y: number}}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
this.friction = this.body.friction;
|
2018-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactSprite#maxVel
|
|
|
|
* @type {{x: number, y: number}}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
this.maxVel = this.body.maxVel;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = ImpactSprite;
|