2017-11-21 16:54:20 +00:00
|
|
|
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');
|
2018-01-30 19:16:00 +00:00
|
|
|
var Pipeline = require('../../gameobjects/components/Pipeline');
|
2017-11-21 16:54:20 +00:00
|
|
|
var Image = require('../../gameobjects/image/Image');
|
|
|
|
var Vector2 = require('../../math/Vector2');
|
|
|
|
|
|
|
|
var MatterImage = new Class({
|
|
|
|
|
|
|
|
Extends: Image,
|
|
|
|
|
|
|
|
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,
|
2017-11-27 03:45:03 +00:00
|
|
|
Components.SetBody,
|
2017-11-22 14:13:25 +00:00
|
|
|
Components.Sleep,
|
2017-11-21 16:54:20 +00:00
|
|
|
Components.Static,
|
|
|
|
Components.Transform,
|
2018-01-30 19:16:00 +00:00
|
|
|
Components.Velocity,
|
|
|
|
Pipeline
|
2017-11-21 16:54:20 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
// x/y is the center of the Image / Body, just like other default Game Objects
|
|
|
|
function MatterImage (world, x, y, texture, frame, options)
|
|
|
|
{
|
|
|
|
GameObject.call(this, world.scene, 'Image');
|
|
|
|
|
|
|
|
this.setTexture(texture, frame);
|
|
|
|
this.setSizeToFrame();
|
|
|
|
this.setOrigin();
|
|
|
|
|
2017-11-27 03:45:03 +00:00
|
|
|
this.world = world;
|
2017-11-21 16:54:20 +00:00
|
|
|
|
2017-11-27 03:45:03 +00:00
|
|
|
this._tempVec2 = new Vector2(x, y);
|
2017-11-21 16:54:20 +00:00
|
|
|
|
2017-11-27 03:45:03 +00:00
|
|
|
var shape = GetFastValue(options, 'shape', null);
|
2017-11-21 16:54:20 +00:00
|
|
|
|
2017-11-27 03:45:03 +00:00
|
|
|
if (!shape)
|
2017-11-21 16:54:20 +00:00
|
|
|
{
|
|
|
|
this.body = Bodies.rectangle(x, y, this.width, this.height, options);
|
|
|
|
|
2017-11-27 03:45:03 +00:00
|
|
|
this.body.gameObject = this;
|
2017-11-22 02:25:06 +00:00
|
|
|
|
2017-11-27 03:45:03 +00:00
|
|
|
if (GetFastValue(options, 'addToWorld', true))
|
|
|
|
{
|
|
|
|
world.add(this.body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-11-23 16:54:55 +00:00
|
|
|
{
|
2017-11-27 03:45:03 +00:00
|
|
|
this.setBody(shape, options);
|
2017-11-23 16:54:55 +00:00
|
|
|
}
|
2017-11-21 16:54:20 +00:00
|
|
|
|
|
|
|
this.setPosition(x, y);
|
2018-01-30 19:16:00 +00:00
|
|
|
|
|
|
|
this.initPipeline('TextureTintPipeline');
|
2017-11-21 16:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = MatterImage;
|