2017-02-23 03:54:54 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Components = require('../components');
|
2017-12-15 04:07:45 +00:00
|
|
|
var GameObject = require('../GameObject');
|
2017-02-23 03:54:54 +00:00
|
|
|
var SpriteRender = require('./SpriteRender');
|
|
|
|
|
|
|
|
var Sprite = new Class({
|
|
|
|
|
2017-04-05 01:10:48 +00:00
|
|
|
Extends: GameObject,
|
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
Mixins: [
|
|
|
|
Components.Alpha,
|
|
|
|
Components.BlendMode,
|
2018-02-01 00:50:15 +00:00
|
|
|
Components.Depth,
|
2017-04-04 22:59:16 +00:00
|
|
|
Components.Flip,
|
2017-03-02 02:06:13 +00:00
|
|
|
Components.GetBounds,
|
|
|
|
Components.Origin,
|
2018-01-29 21:46:48 +00:00
|
|
|
Components.Pipeline,
|
2017-02-23 03:54:54 +00:00
|
|
|
Components.ScaleMode,
|
2017-07-04 11:01:27 +00:00
|
|
|
Components.ScrollFactor,
|
2017-03-02 02:06:13 +00:00
|
|
|
Components.Size,
|
|
|
|
Components.Texture,
|
2017-07-04 11:01:27 +00:00
|
|
|
Components.Tint,
|
2017-03-02 02:06:13 +00:00
|
|
|
Components.Transform,
|
2017-02-23 03:54:54 +00:00
|
|
|
Components.Visible,
|
|
|
|
SpriteRender
|
|
|
|
],
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
function Sprite (scene, x, y, texture, frame)
|
2017-02-23 03:54:54 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
GameObject.call(this, scene, 'Sprite');
|
2017-02-23 03:54:54 +00:00
|
|
|
|
2017-04-04 22:59:16 +00:00
|
|
|
this.anims = new Components.Animation(this);
|
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
this.setTexture(texture, frame);
|
2017-03-02 02:06:13 +00:00
|
|
|
this.setPosition(x, y);
|
2017-03-02 04:00:39 +00:00
|
|
|
this.setSizeToFrame();
|
2017-03-15 23:44:39 +00:00
|
|
|
this.setOrigin();
|
2018-01-29 21:46:48 +00:00
|
|
|
this.initPipeline('TextureTintPipeline');
|
2017-04-04 22:59:16 +00:00
|
|
|
},
|
|
|
|
|
2017-07-04 22:43:13 +00:00
|
|
|
preUpdate: function (time, delta)
|
2017-04-04 22:59:16 +00:00
|
|
|
{
|
2017-07-04 22:43:13 +00:00
|
|
|
this.anims.update(time, delta);
|
2017-04-05 03:41:53 +00:00
|
|
|
},
|
|
|
|
|
2017-09-26 08:45:04 +00:00
|
|
|
play: function (key, ignoreIfPlaying, startFrame)
|
2017-04-05 03:41:53 +00:00
|
|
|
{
|
2017-09-26 08:45:04 +00:00
|
|
|
this.anims.play(key, ignoreIfPlaying, startFrame);
|
2017-08-10 04:17:26 +00:00
|
|
|
|
|
|
|
return this;
|
2017-04-12 23:35:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
toJSON: function ()
|
|
|
|
{
|
|
|
|
var data = Components.ToJSON(this);
|
|
|
|
|
|
|
|
// Extra Sprite data is added here
|
|
|
|
|
|
|
|
return data;
|
2017-01-24 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Sprite;
|