Skip to content

Commit aac7830

Browse files
committed
Added per Shape factories
1 parent 5e126b8 commit aac7830

8 files changed

Lines changed: 194 additions & 94 deletions

File tree

src/gameobjects/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,18 @@ var GameObjects = {
5757
Particles: require('./particles/ParticleManagerFactory'),
5858
PathFollower: require('./pathfollower/PathFollowerFactory'),
5959
RenderTexture: require('./rendertexture/RenderTextureFactory'),
60-
Shape: require('./shape/ShapeFactory'),
6160
Sprite: require('./sprite/SpriteFactory'),
6261
StaticBitmapText: require('./bitmaptext/static/BitmapTextFactory'),
6362
Text: require('./text/static/TextFactory'),
6463
TileSprite: require('./tilesprite/TileSpriteFactory'),
65-
Zone: require('./zone/ZoneFactory')
64+
Zone: require('./zone/ZoneFactory'),
65+
66+
// Shapes
67+
Arc: require('./shape/arc/ArcFactory'),
68+
Ellipse: require('./shape/ellipse/EllipseFactory'),
69+
Polygon: require('./shape/polygon/PolygonFactory'),
70+
Rectangle: require('./shape/rectangle/RectangleFactory'),
71+
Triangle: require('./shape/triangle/TriangleFactory')
6672
},
6773

6874
Creators: {
@@ -74,7 +80,6 @@ var GameObjects = {
7480
Image: require('./image/ImageCreator'),
7581
Particles: require('./particles/ParticleManagerCreator'),
7682
RenderTexture: require('./rendertexture/RenderTextureCreator'),
77-
Shape: require('./shape/ShapeCreator'),
7883
Sprite: require('./sprite/SpriteCreator'),
7984
StaticBitmapText: require('./bitmaptext/static/BitmapTextCreator'),
8085
Text: require('./text/static/TextCreator'),

src/gameobjects/shape/ShapeCreator.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/gameobjects/shape/ShapeFactory.js

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var Arc = require('./Arc');
8+
var GameObjectFactory = require('../../GameObjectFactory');
9+
10+
/**
11+
* Creates a new Arc Shape Game Object and adds it to the Scene.
12+
*
13+
* Note: This method will only be available if the Arc Game Object has been built into Phaser.
14+
*
15+
* @method Phaser.GameObjects.GameObjectFactory#arc
16+
* @since 3.13.0
17+
*
18+
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
19+
* @param {number} [y=0] - The vertical position of this Game Object in the world.
20+
* @param {number} [radius=128] - The radius of the arc.
21+
* @param {number} [fillColor=0xffffff] - The color the arc will be filled with, i.e. 0xff0000 for red.
22+
* @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.
23+
* @param {number} [startAngle=0] - The start angle of the arc, in degrees.
24+
* @param {number} [endAngle=360] - The end angle of the arc, in degrees.
25+
* @param {boolean} [anticlockwise=false] - The winding order of the start and end angles.
26+
*
27+
* @return {Phaser.GameObjects.Arc} The Game Object that was created.
28+
*/
29+
GameObjectFactory.register('arc', function (x, y, radius, fillColor, fillAlpha, startAngle, endAngle, anticlockwise)
30+
{
31+
return this.displayList.add(new Arc(this.scene, x, y, radius, fillColor, fillAlpha, startAngle, endAngle, anticlockwise));
32+
});
33+
34+
/**
35+
* Creates a new Circle Shape Game Object and adds it to the Scene.
36+
*
37+
* A Circle is an Arc with no defined start and end angle, making it render as a complete circle.
38+
*
39+
* Note: This method will only be available if the Arc Game Object has been built into Phaser.
40+
*
41+
* @method Phaser.GameObjects.GameObjectFactory#circle
42+
* @since 3.13.0
43+
*
44+
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
45+
* @param {number} [y=0] - The vertical position of this Game Object in the world.
46+
* @param {number} [radius=128] - The radius of the circle.
47+
* @param {number} [fillColor=0xffffff] - The color the circle will be filled with, i.e. 0xff0000 for red.
48+
* @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.
49+
*
50+
* @return {Phaser.GameObjects.Arc} The Game Object that was created.
51+
*/
52+
GameObjectFactory.register('circle', function (x, y, radius, fillColor, fillAlpha)
53+
{
54+
return this.displayList.add(new Arc(this.scene, x, y, radius, fillColor, fillAlpha));
55+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var Ellipse = require('./Ellipse');
8+
var GameObjectFactory = require('../../GameObjectFactory');
9+
10+
/**
11+
* Creates a new Ellipse Shape Game Object and adds it to the Scene.
12+
*
13+
* Note: This method will only be available if the Ellipse Game Object has been built into Phaser.
14+
*
15+
* @method Phaser.GameObjects.GameObjectFactory#ellipse
16+
* @since 3.13.0
17+
*
18+
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
19+
* @param {number} [y=0] - The vertical position of this Game Object in the world.
20+
* @param {number} [width=128] - The width of the ellipse. An ellipse with equal width and height renders as a circle.
21+
* @param {number} [height=128] - The height of the ellipse. An ellipse with equal width and height renders as a circle.
22+
* @param {number} [fillColor=0xffffff] - The color the ellipse will be filled with, i.e. 0xff0000 for red.
23+
* @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.
24+
* @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.
25+
*
26+
* @return {Phaser.GameObjects.Ellipse} The Game Object that was created.
27+
*/
28+
GameObjectFactory.register('ellipse', function (x, y, width, height, fillColor, fillAlpha, smoothness)
29+
{
30+
return this.displayList.add(new Ellipse(this.scene, x, y, width, height, fillColor, fillAlpha, smoothness));
31+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var GameObjectFactory = require('../../GameObjectFactory');
8+
var Polygon = require('./Polygon');
9+
10+
/**
11+
* Creates a new Polygon Shape Game Object and adds it to the Scene.
12+
*
13+
* The points can be set from a variety of formats:
14+
*
15+
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
16+
* - An array of objects with public x/y properties: `[obj1, obj2, ...]`
17+
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
18+
* - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]`
19+
*
20+
* Note: This method will only be available if the Polygon Game Object has been built into Phaser.
21+
*
22+
* @method Phaser.GameObjects.GameObjectFactory#polygon
23+
* @since 3.13.0
24+
*
25+
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
26+
* @param {number} [y=0] - The vertical position of this Game Object in the world.
27+
* @param {any} [points] - The points that make up the polygon.
28+
* @param {number} [fillColor=0xffffff] - The color the polygon will be filled with, i.e. 0xff0000 for red.
29+
* @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.
30+
*
31+
* @return {Phaser.GameObjects.Polygon} The Game Object that was created.
32+
*/
33+
GameObjectFactory.register('polygon', function (x, y, points, fillColor, fillAlpha)
34+
{
35+
return this.displayList.add(new Polygon(this.scene, x, y, points, fillColor, fillAlpha));
36+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var GameObjectFactory = require('../../GameObjectFactory');
8+
var Rectangle = require('./Rectangle');
9+
10+
/**
11+
* Creates a new Rectangle Shape Game Object and adds it to the Scene.
12+
*
13+
* Note: This method will only be available if the Rectangle Game Object has been built into Phaser.
14+
*
15+
* @method Phaser.GameObjects.GameObjectFactory#rectangle
16+
* @since 3.13.0
17+
*
18+
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
19+
* @param {number} [y=0] - The vertical position of this Game Object in the world.
20+
* @param {number} [width=128] - The width of the rectangle.
21+
* @param {number} [height=128] - The height of the rectangle.
22+
* @param {number} [fillColor] - The color the rectangle will be filled with, i.e. 0xff0000 for red.
23+
* @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.
24+
*
25+
* @return {Phaser.GameObjects.Rectangle} The Game Object that was created.
26+
*/
27+
GameObjectFactory.register('rectangle', function (x, y, width, height, fillColor, fillAlpha)
28+
{
29+
return this.displayList.add(new Rectangle(this.scene, x, y, width, height, fillColor, fillAlpha));
30+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var GameObjectFactory = require('../../GameObjectFactory');
8+
var Triangle = require('./Triangle');
9+
10+
/**
11+
* Creates a new Triangle Shape Game Object and adds it to the Scene.
12+
*
13+
* Note: This method will only be available if the Triangle Game Object has been built into Phaser.
14+
*
15+
* @method Phaser.GameObjects.GameObjectFactory#triangle
16+
* @since 3.13.0
17+
*
18+
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
19+
* @param {number} [y=0] - The vertical position of this Game Object in the world.
20+
* @param {number} [x1=0] - The horizontal position of the first point in the triangle.
21+
* @param {number} [y1=128] - The horizontal position of the first point in the triangle.
22+
* @param {number} [x2=64] - The horizontal position of the second point in the triangle.
23+
* @param {number} [y2=0] - The horizontal position of the second point in the triangle.
24+
* @param {number} [x3=128] - The horizontal position of the third point in the triangle.
25+
* @param {number} [y3=128] - The horizontal position of the third point in the triangle.
26+
* @param {number} [fillColor] - The color the triangle will be filled with, i.e. 0xff0000 for red.
27+
* @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.
28+
*
29+
* @return {Phaser.GameObjects.Triangle} The Game Object that was created.
30+
*/
31+
GameObjectFactory.register('triangle', function (x, y, x1, y1, x2, y2, x3, y3, fillColor, fillAlpha)
32+
{
33+
return this.displayList.add(new Triangle(this.scene, x, y, x1, y1, x2, y2, x3, y3, fillColor, fillAlpha));
34+
});

0 commit comments

Comments
 (0)