phaser/src/gameobjects/sprite/Sprite.js

67 lines
1.4 KiB
JavaScript
Raw Normal View History

var Class = require('../../utils/Class');
var Components = require('../components');
2017-12-15 04:07:45 +00:00
var GameObject = require('../GameObject');
var SpriteRender = require('./SpriteRender');
var Sprite = new Class({
2017-04-05 01:10:48 +00:00
Extends: GameObject,
Mixins: [
Components.Alpha,
Components.BlendMode,
Components.Depth,
2017-04-04 22:59:16 +00:00
Components.Flip,
Components.GetBounds,
Components.Origin,
2018-01-29 21:46:48 +00:00
Components.Pipeline,
Components.ScaleMode,
Components.ScrollFactor,
Components.Size,
Components.Texture,
Components.Tint,
Components.Transform,
Components.Visible,
SpriteRender
],
initialize:
function Sprite (scene, x, y, texture, frame)
{
GameObject.call(this, scene, 'Sprite');
2017-04-04 22:59:16 +00:00
this.anims = new Components.Animation(this);
this.setTexture(texture, frame);
this.setPosition(x, y);
this.setSizeToFrame();
this.setOrigin();
2018-01-29 21:46:48 +00:00
this.initPipeline('TextureTintPipeline');
2017-04-04 22:59:16 +00:00
},
preUpdate: function (time, delta)
2017-04-04 22:59:16 +00:00
{
this.anims.update(time, delta);
2017-04-05 03:41:53 +00:00
},
play: function (key, ignoreIfPlaying, startFrame)
2017-04-05 03:41:53 +00:00
{
this.anims.play(key, ignoreIfPlaying, startFrame);
return this;
},
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;