phaser/v3/src/gameobjects/sprite/Sprite.js

66 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-01-24 18:08:56 +00:00
var Class = require('../../utils/Class');
2017-01-24 18:08:56 +00:00
var GameObject = require('../GameObject');
var Components = require('../components');
var SpriteRender = require('./SpriteRender');
var Sprite = new Class({
2017-04-05 01:10:48 +00:00
Extends: GameObject,
Mixins: [
Components.Alpha,
Components.BlendMode,
2017-04-04 22:59:16 +00:00
Components.Flip,
Components.GetBounds,
Components.Origin,
2017-04-07 01:49:15 +00:00
Components.RenderTarget,
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();
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, startFrame)
{
this.anims.play(key, 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;