2017-11-21 16:54:20 +00:00
|
|
|
var AnimationComponent = require('../../gameobjects/components/Animation');
|
|
|
|
var Bodies = require('./lib/factory/Bodies');
|
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var Components = require('./components');
|
|
|
|
var GameObject = require('../../gameobjects/GameObject');
|
|
|
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
|
|
|
var Sprite = require('../../gameobjects/sprite/Sprite');
|
|
|
|
var Vector2 = require('../../math/Vector2');
|
|
|
|
|
|
|
|
var MatterSprite = new Class({
|
|
|
|
|
|
|
|
Extends: Sprite,
|
|
|
|
|
|
|
|
Mixins: [
|
|
|
|
Components.Bounce,
|
2017-11-22 02:25:06 +00:00
|
|
|
Components.Collision,
|
2017-11-21 16:54:20 +00:00
|
|
|
Components.Force,
|
|
|
|
Components.Friction,
|
2017-11-22 17:11:09 +00:00
|
|
|
Components.Gravity,
|
2017-11-21 16:54:20 +00:00
|
|
|
Components.Mass,
|
2017-11-22 14:13:25 +00:00
|
|
|
Components.Sensor,
|
|
|
|
Components.Sleep,
|
2017-11-21 16:54:20 +00:00
|
|
|
Components.Static,
|
|
|
|
Components.Transform,
|
|
|
|
Components.Velocity
|
|
|
|
],
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
// x/y is the center of the Sprite / Body, just like other default Game Objects
|
|
|
|
function MatterSprite (world, x, y, texture, frame, options)
|
|
|
|
{
|
|
|
|
GameObject.call(this, world.scene, 'Image');
|
|
|
|
|
|
|
|
this.anims = new AnimationComponent(this);
|
|
|
|
|
|
|
|
this.setTexture(texture, frame);
|
|
|
|
this.setSizeToFrame();
|
|
|
|
this.setOrigin();
|
|
|
|
|
|
|
|
this._tempVec2 = new Vector2();
|
|
|
|
|
|
|
|
var isCircle = GetFastValue(options, 'isCircle', false);
|
|
|
|
|
|
|
|
if (isCircle)
|
|
|
|
{
|
|
|
|
var radius = GetFastValue(options, 'radius', Math.max(this.width, this.height) / 2);
|
|
|
|
|
|
|
|
this.body = Bodies.circle(x, y, radius, options);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.body = Bodies.rectangle(x, y, this.width, this.height, options);
|
|
|
|
}
|
|
|
|
|
2017-11-22 02:25:06 +00:00
|
|
|
this.body.gameObject = this;
|
|
|
|
|
2017-11-22 14:13:25 +00:00
|
|
|
this.world = world;
|
|
|
|
|
2017-11-21 16:54:20 +00:00
|
|
|
world.add(this.body);
|
|
|
|
|
|
|
|
this.setPosition(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = MatterSprite;
|