mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Added per Shape factories
This commit is contained in:
parent
5e126b80fa
commit
aac783064f
8 changed files with 194 additions and 94 deletions
|
@ -57,12 +57,18 @@ var GameObjects = {
|
|||
Particles: require('./particles/ParticleManagerFactory'),
|
||||
PathFollower: require('./pathfollower/PathFollowerFactory'),
|
||||
RenderTexture: require('./rendertexture/RenderTextureFactory'),
|
||||
Shape: require('./shape/ShapeFactory'),
|
||||
Sprite: require('./sprite/SpriteFactory'),
|
||||
StaticBitmapText: require('./bitmaptext/static/BitmapTextFactory'),
|
||||
Text: require('./text/static/TextFactory'),
|
||||
TileSprite: require('./tilesprite/TileSpriteFactory'),
|
||||
Zone: require('./zone/ZoneFactory')
|
||||
Zone: require('./zone/ZoneFactory'),
|
||||
|
||||
// Shapes
|
||||
Arc: require('./shape/arc/ArcFactory'),
|
||||
Ellipse: require('./shape/ellipse/EllipseFactory'),
|
||||
Polygon: require('./shape/polygon/PolygonFactory'),
|
||||
Rectangle: require('./shape/rectangle/RectangleFactory'),
|
||||
Triangle: require('./shape/triangle/TriangleFactory')
|
||||
},
|
||||
|
||||
Creators: {
|
||||
|
@ -74,7 +80,6 @@ var GameObjects = {
|
|||
Image: require('./image/ImageCreator'),
|
||||
Particles: require('./particles/ParticleManagerCreator'),
|
||||
RenderTexture: require('./rendertexture/RenderTextureCreator'),
|
||||
Shape: require('./shape/ShapeCreator'),
|
||||
Sprite: require('./sprite/SpriteCreator'),
|
||||
StaticBitmapText: require('./bitmaptext/static/BitmapTextCreator'),
|
||||
Text: require('./text/static/TextCreator'),
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var GameObjectCreator = require('../GameObjectCreator');
|
||||
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
|
||||
var Rectangle = require('./rectangle/Rectangle');
|
||||
|
||||
/**
|
||||
* Creates a new Zone Game Object and returns it.
|
||||
*
|
||||
* Note: This method will only be available if the Zone Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectCreator#rectangle
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {object} config - The configuration object this Game Object will use to create itself.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Zone} The Game Object that was created.
|
||||
*/
|
||||
GameObjectCreator.register('rectangle', function (config)
|
||||
{
|
||||
var x = GetAdvancedValue(config, 'x', 0);
|
||||
var y = GetAdvancedValue(config, 'y', 0);
|
||||
var width = GetAdvancedValue(config, 'width', 1);
|
||||
var height = GetAdvancedValue(config, 'height', width);
|
||||
|
||||
return new Rectangle(this.scene, x, y, width, height);
|
||||
});
|
||||
|
||||
// When registering a factory function 'this' refers to the GameObjectCreator context.
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var Arc = require('./arc/Arc');
|
||||
var Ellipse = require('./ellipse/Ellipse');
|
||||
var GameObjectFactory = require('../GameObjectFactory');
|
||||
var Polygon = require('./polygon/Polygon');
|
||||
var Rectangle = require('./rectangle/Rectangle');
|
||||
var Triangle = require('./triangle/Triangle');
|
||||
|
||||
/**
|
||||
* Creates a new Image Game Object and adds it to the Scene.
|
||||
*
|
||||
* Note: This method will only be available if the Image Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectFactory#rectangle
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {number} x - The horizontal position of this Game Object in the world.
|
||||
* @param {number} y - The vertical position of this Game Object in the world.
|
||||
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
||||
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Image} The Game Object that was created.
|
||||
*/
|
||||
GameObjectFactory.register('rectangle', function (x, y, width, height, fillColor, fillAlpha)
|
||||
{
|
||||
return this.displayList.add(new Rectangle(this.scene, x, y, width, height, fillColor, fillAlpha));
|
||||
});
|
||||
|
||||
GameObjectFactory.register('triangle', function (x, y, x1, y1, x2, y2, x3, y3, fillColor, fillAlpha)
|
||||
{
|
||||
return this.displayList.add(new Triangle(this.scene, x, y, x1, y1, x2, y2, x3, y3, fillColor, fillAlpha));
|
||||
});
|
||||
|
||||
GameObjectFactory.register('arc', function (x, y, radius, fillColor, fillAlpha, startAngle, endAngle, anticlockwise)
|
||||
{
|
||||
return this.displayList.add(new Arc(this.scene, x, y, radius, fillColor, fillAlpha, startAngle, endAngle, anticlockwise));
|
||||
});
|
||||
|
||||
GameObjectFactory.register('circle', function (x, y, radius, fillColor, fillAlpha)
|
||||
{
|
||||
return this.displayList.add(new Arc(this.scene, x, y, radius, fillColor, fillAlpha));
|
||||
});
|
||||
|
||||
GameObjectFactory.register('polygon', function (x, y, points, fillColor, fillAlpha)
|
||||
{
|
||||
return this.displayList.add(new Polygon(this.scene, x, y, points, fillColor, fillAlpha));
|
||||
});
|
||||
|
||||
GameObjectFactory.register('ellipse', function (x, y, width, height, fillColor, fillAlpha, smoothness)
|
||||
{
|
||||
return this.displayList.add(new Ellipse(this.scene, x, y, width, height, fillColor, fillAlpha, smoothness));
|
||||
});
|
||||
|
55
src/gameobjects/shape/arc/ArcFactory.js
Normal file
55
src/gameobjects/shape/arc/ArcFactory.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var Arc = require('./Arc');
|
||||
var GameObjectFactory = require('../../GameObjectFactory');
|
||||
|
||||
/**
|
||||
* Creates a new Arc Shape Game Object and adds it to the Scene.
|
||||
*
|
||||
* Note: This method will only be available if the Arc Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectFactory#arc
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
|
||||
* @param {number} [y=0] - The vertical position of this Game Object in the world.
|
||||
* @param {number} [radius=128] - The radius of the arc.
|
||||
* @param {number} [fillColor=0xffffff] - The color the arc will be filled with, i.e. 0xff0000 for red.
|
||||
* @param {number} [fillAlpha=1] - The alpha the arc will be filled with. You can also set the alpha of the overall Shape using its `alpha` property.
|
||||
* @param {number} [startAngle=0] - The start angle of the arc, in degrees.
|
||||
* @param {number} [endAngle=360] - The end angle of the arc, in degrees.
|
||||
* @param {boolean} [anticlockwise=false] - The winding order of the start and end angles.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Arc} The Game Object that was created.
|
||||
*/
|
||||
GameObjectFactory.register('arc', function (x, y, radius, fillColor, fillAlpha, startAngle, endAngle, anticlockwise)
|
||||
{
|
||||
return this.displayList.add(new Arc(this.scene, x, y, radius, fillColor, fillAlpha, startAngle, endAngle, anticlockwise));
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a new Circle Shape Game Object and adds it to the Scene.
|
||||
*
|
||||
* A Circle is an Arc with no defined start and end angle, making it render as a complete circle.
|
||||
*
|
||||
* Note: This method will only be available if the Arc Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectFactory#circle
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
|
||||
* @param {number} [y=0] - The vertical position of this Game Object in the world.
|
||||
* @param {number} [radius=128] - The radius of the circle.
|
||||
* @param {number} [fillColor=0xffffff] - The color the circle will be filled with, i.e. 0xff0000 for red.
|
||||
* @param {number} [fillAlpha=1] - The alpha the circle will be filled with. You can also set the alpha of the overall Shape using its `alpha` property.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Arc} The Game Object that was created.
|
||||
*/
|
||||
GameObjectFactory.register('circle', function (x, y, radius, fillColor, fillAlpha)
|
||||
{
|
||||
return this.displayList.add(new Arc(this.scene, x, y, radius, fillColor, fillAlpha));
|
||||
});
|
31
src/gameobjects/shape/ellipse/EllipseFactory.js
Normal file
31
src/gameobjects/shape/ellipse/EllipseFactory.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var Ellipse = require('./Ellipse');
|
||||
var GameObjectFactory = require('../../GameObjectFactory');
|
||||
|
||||
/**
|
||||
* Creates a new Ellipse Shape Game Object and adds it to the Scene.
|
||||
*
|
||||
* Note: This method will only be available if the Ellipse Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectFactory#ellipse
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
|
||||
* @param {number} [y=0] - The vertical position of this Game Object in the world.
|
||||
* @param {number} [width=128] - The width of the ellipse. An ellipse with equal width and height renders as a circle.
|
||||
* @param {number} [height=128] - The height of the ellipse. An ellipse with equal width and height renders as a circle.
|
||||
* @param {number} [fillColor=0xffffff] - The color the ellipse will be filled with, i.e. 0xff0000 for red.
|
||||
* @param {number} [fillAlpha=1] - The alpha the ellipse will be filled with. You can also set the alpha of the overall Shape using its `alpha` property.
|
||||
* @param {number} [smoothness=32] - The number of points used to draw the ellipse. Higher values create smoother renders at the cost of more triangles being drawn.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Ellipse} The Game Object that was created.
|
||||
*/
|
||||
GameObjectFactory.register('ellipse', function (x, y, width, height, fillColor, fillAlpha, smoothness)
|
||||
{
|
||||
return this.displayList.add(new Ellipse(this.scene, x, y, width, height, fillColor, fillAlpha, smoothness));
|
||||
});
|
36
src/gameobjects/shape/polygon/PolygonFactory.js
Normal file
36
src/gameobjects/shape/polygon/PolygonFactory.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var GameObjectFactory = require('../../GameObjectFactory');
|
||||
var Polygon = require('./Polygon');
|
||||
|
||||
/**
|
||||
* Creates a new Polygon Shape Game Object and adds it to the Scene.
|
||||
*
|
||||
* The points can be set from a variety of formats:
|
||||
*
|
||||
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
|
||||
* - An array of objects with public x/y properties: `[obj1, obj2, ...]`
|
||||
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
|
||||
* - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]`
|
||||
*
|
||||
* Note: This method will only be available if the Polygon Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectFactory#polygon
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
|
||||
* @param {number} [y=0] - The vertical position of this Game Object in the world.
|
||||
* @param {any} [points] - The points that make up the polygon.
|
||||
* @param {number} [fillColor=0xffffff] - The color the polygon will be filled with, i.e. 0xff0000 for red.
|
||||
* @param {number} [fillAlpha=1] - The alpha the polygon will be filled with. You can also set the alpha of the overall Shape using its `alpha` property.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Polygon} The Game Object that was created.
|
||||
*/
|
||||
GameObjectFactory.register('polygon', function (x, y, points, fillColor, fillAlpha)
|
||||
{
|
||||
return this.displayList.add(new Polygon(this.scene, x, y, points, fillColor, fillAlpha));
|
||||
});
|
30
src/gameobjects/shape/rectangle/RectangleFactory.js
Normal file
30
src/gameobjects/shape/rectangle/RectangleFactory.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var GameObjectFactory = require('../../GameObjectFactory');
|
||||
var Rectangle = require('./Rectangle');
|
||||
|
||||
/**
|
||||
* Creates a new Rectangle Shape Game Object and adds it to the Scene.
|
||||
*
|
||||
* Note: This method will only be available if the Rectangle Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectFactory#rectangle
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
|
||||
* @param {number} [y=0] - The vertical position of this Game Object in the world.
|
||||
* @param {number} [width=128] - The width of the rectangle.
|
||||
* @param {number} [height=128] - The height of the rectangle.
|
||||
* @param {number} [fillColor] - The color the rectangle will be filled with, i.e. 0xff0000 for red.
|
||||
* @param {number} [fillAlpha] - The alpha the rectangle will be filled with. You can also set the alpha of the overall Shape using its `alpha` property.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Rectangle} The Game Object that was created.
|
||||
*/
|
||||
GameObjectFactory.register('rectangle', function (x, y, width, height, fillColor, fillAlpha)
|
||||
{
|
||||
return this.displayList.add(new Rectangle(this.scene, x, y, width, height, fillColor, fillAlpha));
|
||||
});
|
34
src/gameobjects/shape/triangle/TriangleFactory.js
Normal file
34
src/gameobjects/shape/triangle/TriangleFactory.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var GameObjectFactory = require('../../GameObjectFactory');
|
||||
var Triangle = require('./Triangle');
|
||||
|
||||
/**
|
||||
* Creates a new Triangle Shape Game Object and adds it to the Scene.
|
||||
*
|
||||
* Note: This method will only be available if the Triangle Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectFactory#triangle
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
|
||||
* @param {number} [y=0] - The vertical position of this Game Object in the world.
|
||||
* @param {number} [x1=0] - The horizontal position of the first point in the triangle.
|
||||
* @param {number} [y1=128] - The horizontal position of the first point in the triangle.
|
||||
* @param {number} [x2=64] - The horizontal position of the second point in the triangle.
|
||||
* @param {number} [y2=0] - The horizontal position of the second point in the triangle.
|
||||
* @param {number} [x3=128] - The horizontal position of the third point in the triangle.
|
||||
* @param {number} [y3=128] - The horizontal position of the third point in the triangle.
|
||||
* @param {number} [fillColor] - The color the triangle will be filled with, i.e. 0xff0000 for red.
|
||||
* @param {number} [fillAlpha] - The alpha the triangle will be filled with. You can also set the alpha of the overall Shape using its `alpha` property.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Triangle} The Game Object that was created.
|
||||
*/
|
||||
GameObjectFactory.register('triangle', function (x, y, x1, y1, x2, y2, x3, y3, fillColor, fillAlpha)
|
||||
{
|
||||
return this.displayList.add(new Triangle(this.scene, x, y, x1, y1, x2, y2, x3, y3, fillColor, fillAlpha));
|
||||
});
|
Loading…
Add table
Reference in a new issue