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

38 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-01-24 18:08:56 +00:00
var Sprite = require('./Sprite');
var BuildFromConfig = require('./BuildFromConfig');
var FactoryContainer = require('../FactoryContainer');
2017-01-24 18:08:56 +00:00
var SpriteFactory = {
KEY: 'sprite',
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* At its most basic a Sprite consists of a set of coordinates and a texture that is used when rendered.
* They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input),
* events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases.
*
* @method Phaser.GameObject.Factory#sprite
* @param {number} [x=0] - The x coordinate of the sprite. The coordinate is relative to any parent container this sprite may be in.
* @param {number} [y=0] - The y coordinate of the sprite. The coordinate is relative to any parent container this sprite may be in.
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|Phaser.Video|PIXI.Texture} [key] - The image used as a texture by this display object during rendering. If a string Phaser will get for an entry in the Image Cache. Or it can be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
* @param {string|number} [frame] - If a Texture Atlas or Sprite Sheet is used this allows you to specify the frame to be used. Use either an integer for a Frame ID or a string for a frame name.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.Sprite} The newly created Sprite object.
*/
add: function (x, y, key, frame)
2017-01-24 18:08:56 +00:00
{
return this.children.add(new Sprite(this.state, x, y, key, frame));
2017-01-24 18:08:56 +00:00
},
make: function (config)
2017-01-24 18:08:56 +00:00
{
return BuildFromConfig(this.state, config);
2017-01-24 18:08:56 +00:00
}
};
module.exports = FactoryContainer.register(SpriteFactory);