|
| 1 | +/** |
| 2 | +* @author Richard Davey <rich@photonstorm.com> |
| 3 | +* @copyright 2016 Photon Storm Ltd. |
| 4 | +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
| 5 | +*/ |
| 6 | + |
| 7 | +var Sprite = require('./Sprite'); |
| 8 | +var FactoryContainer = require('../../gameobjects/FactoryContainer'); |
| 9 | + |
| 10 | +var SpriteFactory = { |
| 11 | + |
| 12 | + KEY: 'sprite', |
| 13 | + |
| 14 | + /** |
| 15 | + * Create a new Sprite with specific position and sprite sheet key. |
| 16 | + * |
| 17 | + * At its most basic a Sprite consists of a set of coordinates and a texture that is used when rendered. |
| 18 | + * They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input), |
| 19 | + * events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases. |
| 20 | + * |
| 21 | + * @method Phaser.GameObject.Factory#sprite |
| 22 | + * @param {number} [x=0] - The x coordinate of the sprite. The coordinate is relative to any parent container this sprite may be in. |
| 23 | + * @param {number} [y=0] - The y coordinate of the sprite. The coordinate is relative to any parent container this sprite may be in. |
| 24 | + * @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. |
| 25 | + * @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. |
| 26 | + * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. |
| 27 | + * @return {Phaser.Sprite} The newly created Sprite object. |
| 28 | + */ |
| 29 | + add: function (x, y, key, frame, group) |
| 30 | + { |
| 31 | + if (group === undefined) { group = this.state; } |
| 32 | + |
| 33 | + // console.log('ImageFactory.add', key, x, y, frame, group); |
| 34 | + // console.log('into State', this.state); |
| 35 | + |
| 36 | + return group.children.add(new Sprite(this.state, x, y, key, frame)); |
| 37 | + }, |
| 38 | + |
| 39 | + make: function (x, y, key, frame) |
| 40 | + { |
| 41 | + // console.log('ImageFactory.make', key, x, y, frame); |
| 42 | + |
| 43 | + return new Sprite(this.state, x, y, key, frame); |
| 44 | + } |
| 45 | + |
| 46 | +}; |
| 47 | + |
| 48 | +module.exports = FactoryContainer.register(SpriteFactory); |
0 commit comments