Skip to content

Commit 8bc4d06

Browse files
committed
Added IsoTriangle and project setting
1 parent 266f993 commit 8bc4d06

9 files changed

Lines changed: 404 additions & 28 deletions

File tree

src/gameobjects/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var GameObjects = {
4242
Arc: require('./shape/arc/Arc'),
4343
Ellipse: require('./shape/ellipse/Ellipse'),
4444
IsoBox: require('./shape/isobox/IsoBox'),
45+
IsoTriangle: require('./shape/isotriangle/IsoTriangle'),
4546
Line: require('./shape/line/Line'),
4647
Polygon: require('./shape/polygon/Polygon'),
4748
Rectangle: require('./shape/rectangle/Rectangle'),
@@ -70,6 +71,7 @@ var GameObjects = {
7071
Arc: require('./shape/arc/ArcFactory'),
7172
Ellipse: require('./shape/ellipse/EllipseFactory'),
7273
IsoBox: require('./shape/isobox/IsoBoxFactory'),
74+
IsoTriangle: require('./shape/isotriangle/IsoTriangleFactory'),
7375
Line: require('./shape/line/LineFactory'),
7476
Polygon: require('./shape/polygon/PolygonFactory'),
7577
Rectangle: require('./shape/rectangle/RectangleFactory'),

src/gameobjects/shape/isobox/IsoBox.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ var IsoBox = new Class({
4343

4444
Shape.call(this, scene, 'IsoBox', null);
4545

46+
this.projection = 4;
47+
4648
this.fillTop = fillTop;
4749
this.fillLeft = fillLeft;
4850
this.fillRight = fillRight;
@@ -59,6 +61,13 @@ var IsoBox = new Class({
5961
this.updateDisplayOrigin();
6062
},
6163

64+
setProjection: function (value)
65+
{
66+
this.projection = value;
67+
68+
return this;
69+
},
70+
6271
setFaces: function (showTop, showLeft, showRight)
6372
{
6473
if (showTop === undefined) { showTop = true; }

src/gameobjects/shape/isobox/IsoBoxWebGLRenderer.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ var IsoBoxWebGLRenderer = function (renderer, src, interpolationPercentage, came
5555
var size = src.width;
5656
var height = src.height;
5757

58+
var sizeA = size / 2;
59+
var sizeB = size / src.projection;
60+
5861
var alpha = camera.alpha * src.alpha;
5962

6063
if (!src.isFilled)
@@ -82,17 +85,17 @@ var IsoBoxWebGLRenderer = function (renderer, src, interpolationPercentage, came
8285
{
8386
tint = Utils.getTintAppendFloatAlphaAndSwap(src.fillTop, alpha);
8487

85-
x0 = calcMatrix.getX(-size / 2, -height);
86-
y0 = calcMatrix.getY(-size / 2, -height);
88+
x0 = calcMatrix.getX(-sizeA, -height);
89+
y0 = calcMatrix.getY(-sizeA, -height);
8790

88-
x1 = calcMatrix.getX(0, -size / 4 - height);
89-
y1 = calcMatrix.getY(0, -size / 4 - height);
91+
x1 = calcMatrix.getX(0, -sizeB - height);
92+
y1 = calcMatrix.getY(0, -sizeB - height);
9093

91-
x2 = calcMatrix.getX(size / 2, -height);
92-
y2 = calcMatrix.getY(size / 2, -height);
94+
x2 = calcMatrix.getX(sizeA, -height);
95+
y2 = calcMatrix.getY(sizeA, -height);
9396

94-
x3 = calcMatrix.getX(0, size / 4 - height);
95-
y3 = calcMatrix.getY(0, size / 4 - height);
97+
x3 = calcMatrix.getX(0, sizeB - height);
98+
y3 = calcMatrix.getY(0, sizeB - height);
9699

97100
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
98101
}
@@ -103,17 +106,17 @@ var IsoBoxWebGLRenderer = function (renderer, src, interpolationPercentage, came
103106
{
104107
tint = Utils.getTintAppendFloatAlphaAndSwap(src.fillLeft, alpha);
105108

106-
x0 = calcMatrix.getX(-size / 2, 0);
107-
y0 = calcMatrix.getY(-size / 2, 0);
109+
x0 = calcMatrix.getX(-sizeA, 0);
110+
y0 = calcMatrix.getY(-sizeA, 0);
108111

109-
x1 = calcMatrix.getX(0, size / 4);
110-
y1 = calcMatrix.getY(0, size / 4);
112+
x1 = calcMatrix.getX(0, sizeB);
113+
y1 = calcMatrix.getY(0, sizeB);
111114

112-
x2 = calcMatrix.getX(0, size / 4 - height);
113-
y2 = calcMatrix.getY(0, size / 4 - height);
115+
x2 = calcMatrix.getX(0, sizeB - height);
116+
y2 = calcMatrix.getY(0, sizeB - height);
114117

115-
x3 = calcMatrix.getX(-size / 2, -height);
116-
y3 = calcMatrix.getY(-size / 2, -height);
118+
x3 = calcMatrix.getX(-sizeA, -height);
119+
y3 = calcMatrix.getY(-sizeA, -height);
117120

118121
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
119122
}
@@ -124,17 +127,17 @@ var IsoBoxWebGLRenderer = function (renderer, src, interpolationPercentage, came
124127
{
125128
tint = Utils.getTintAppendFloatAlphaAndSwap(src.fillRight, alpha);
126129

127-
x0 = calcMatrix.getX(size / 2, 0);
128-
y0 = calcMatrix.getY(size / 2, 0);
130+
x0 = calcMatrix.getX(sizeA, 0);
131+
y0 = calcMatrix.getY(sizeA, 0);
129132

130-
x1 = calcMatrix.getX(0, size / 4);
131-
y1 = calcMatrix.getY(0, size / 4);
133+
x1 = calcMatrix.getX(0, sizeB);
134+
y1 = calcMatrix.getY(0, sizeB);
132135

133-
x2 = calcMatrix.getX(0, size / 4 - height);
134-
y2 = calcMatrix.getY(0, size / 4 - height);
136+
x2 = calcMatrix.getX(0, sizeB - height);
137+
y2 = calcMatrix.getY(0, sizeB - height);
135138

136-
x3 = calcMatrix.getX(size / 2, -height);
137-
y3 = calcMatrix.getY(size / 2, -height);
139+
x3 = calcMatrix.getX(sizeA, -height);
140+
y3 = calcMatrix.getY(sizeA, -height);
138141

139142
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
140143
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 IsoTriangleRender = require('./IsoTriangleRender');
8+
var Class = require('../../../utils/Class');
9+
var Shape = require('../Shape');
10+
11+
/**
12+
* @classdesc
13+
*
14+
* @class IsoTriangle
15+
* @extends Phaser.GameObjects.Shape
16+
* @memberOf Phaser.GameObjects
17+
* @constructor
18+
* @since 3.13.0
19+
*
20+
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
21+
* @param {number} x - The horizontal position of this Game Object in the world.
22+
* @param {number} y - The vertical position of this Game Object in the world.
23+
*/
24+
var IsoTriangle = new Class({
25+
26+
Extends: Shape,
27+
28+
Mixins: [
29+
IsoTriangleRender
30+
],
31+
32+
initialize:
33+
34+
function IsoTriangle (scene, x, y, size, height, reversed, fillTop, fillLeft, fillRight)
35+
{
36+
if (x === undefined) { x = 0; }
37+
if (y === undefined) { y = 0; }
38+
if (size === undefined) { size = 48; }
39+
if (height === undefined) { height = 32; }
40+
if (reversed === undefined) { reversed = false; }
41+
if (fillTop === undefined) { fillTop = 0xeeeeee; }
42+
if (fillLeft === undefined) { fillLeft = 0x999999; }
43+
if (fillRight === undefined) { fillRight = 0xcccccc; }
44+
45+
Shape.call(this, scene, 'IsoTriangle', null);
46+
47+
this.projection = 4;
48+
49+
this.fillTop = fillTop;
50+
this.fillLeft = fillLeft;
51+
this.fillRight = fillRight;
52+
53+
this.showTop = true;
54+
this.showLeft = true;
55+
this.showRight = true;
56+
57+
this.isReversed = reversed;
58+
this.isFilled = true;
59+
60+
this.setPosition(x, y);
61+
this.setSize(size, height);
62+
63+
this.updateDisplayOrigin();
64+
},
65+
66+
setProjection: function (value)
67+
{
68+
this.projection = value;
69+
70+
return this;
71+
},
72+
73+
setReversed: function (reversed)
74+
{
75+
this.isReversed = reversed;
76+
77+
return this;
78+
},
79+
80+
setFaces: function (showTop, showLeft, showRight)
81+
{
82+
if (showTop === undefined) { showTop = true; }
83+
if (showLeft === undefined) { showLeft = true; }
84+
if (showRight === undefined) { showRight = true; }
85+
86+
this.showTop = showTop;
87+
this.showLeft = showLeft;
88+
this.showRight = showRight;
89+
90+
return this;
91+
},
92+
93+
setFillStyle: function (fillTop, fillLeft, fillRight)
94+
{
95+
this.fillTop = fillTop;
96+
this.fillLeft = fillLeft;
97+
this.fillRight = fillRight;
98+
99+
this.isFilled = true;
100+
101+
return this;
102+
}
103+
104+
});
105+
106+
module.exports = IsoTriangle;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
/**
8+
* Renders this Game Object with the Canvas Renderer to the given Camera.
9+
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
10+
* This method should not be called directly. It is a utility function of the Render module.
11+
*
12+
* @method Phaser.GameObjects.IsoTriangle#renderCanvas
13+
* @since 3.13.0
14+
* @private
15+
*
16+
* @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - A reference to the current active Canvas renderer.
17+
* @param {Phaser.GameObjects.IsoTriangle} src - The Game Object being rendered in this call.
18+
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
19+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
20+
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
21+
*/
22+
var IsoTriangleCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
23+
{
24+
};
25+
26+
module.exports = IsoTriangleCanvasRenderer;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 IsoTriangle = require('./IsoTriangle');
9+
10+
/**
11+
* Creates a new IsoTriangle Shape Game Object and adds it to the Scene.
12+
*
13+
* Note: This method will only be available if the IsoTriangle Game Object has been built into Phaser.
14+
*
15+
* @method Phaser.GameObjects.GameObjectFactory#isotriangle
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} [size=48] - The width of the iso triangle in pixels. The left and right faces will be exactly half this value.
21+
* @param {number} [height=32] - The height of the iso triangle. The left and right faces will be this tall. The overall height of the iso triangle will be this value plus half the `size` value.
22+
* @param {boolean} [reversed=false] - Is the iso triangle upside down?
23+
* @param {number} [fillTop=0xeeeeee] - The fill color of the top face of the iso triangle.
24+
* @param {number} [fillLeft=0x999999] - The fill color of the left face of the iso triangle.
25+
* @param {number} [fillRight=0xcccccc] - The fill color of the right face of the iso triangle.
26+
*
27+
* @return {Phaser.GameObjects.IsoTriangle} The Game Object that was created.
28+
*/
29+
GameObjectFactory.register('isotriangle', function (x, y, size, height, reversed, fillTop, fillLeft, fillRight)
30+
{
31+
return this.displayList.add(new IsoTriangle(this.scene, x, y, size, height, reversed, fillTop, fillLeft, fillRight));
32+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 renderWebGL = require('../../../utils/NOOP');
8+
var renderCanvas = require('../../../utils/NOOP');
9+
10+
if (typeof WEBGL_RENDERER)
11+
{
12+
renderWebGL = require('./IsoTriangleWebGLRenderer');
13+
}
14+
15+
if (typeof CANVAS_RENDERER)
16+
{
17+
renderCanvas = require('./IsoTriangleCanvasRenderer');
18+
}
19+
20+
module.exports = {
21+
22+
renderWebGL: renderWebGL,
23+
renderCanvas: renderCanvas
24+
25+
};

0 commit comments

Comments
 (0)