Skip to content

Commit a508cd2

Browse files
committed
Added support for stroke rendering path data
1 parent 2f5f554 commit a508cd2

2 files changed

Lines changed: 71 additions & 5 deletions

File tree

src/gameobjects/shape/rectangle/Rectangle.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,50 @@ var Rectangle = new Class({
3434

3535
function Rectangle (scene, x, y, width, height, fillColor, fillAlpha)
3636
{
37-
Shape.call(this, scene, 'Rectangle', new GeomRectangle(x, y, width, height));
37+
if (x === undefined) { x = 0; }
38+
if (y === undefined) { y = 0; }
39+
if (width === undefined) { width = 128; }
40+
if (height === undefined) { height = 128; }
41+
42+
Shape.call(this, scene, 'Rectangle', new GeomRectangle(0, 0, width, height));
3843

3944
this.setPosition(x, y);
4045
this.setSize(width, height);
4146

42-
this.updateDisplayOrigin();
43-
4447
if (fillColor !== undefined)
4548
{
4649
this.setFillStyle(fillColor, fillAlpha);
4750
}
51+
52+
this.updateDisplayOrigin();
53+
this.updateData();
54+
},
55+
56+
updateData: function ()
57+
{
58+
var path = [];
59+
var rect = this.data;
60+
var line = this._tempLine;
61+
62+
rect.getLineA(line);
63+
64+
path.push(line.x1, line.y1, line.x2, line.y2);
65+
66+
rect.getLineB(line);
67+
68+
path.push(line.x2, line.y2);
69+
70+
rect.getLineC(line);
71+
72+
path.push(line.x2, line.y2);
73+
74+
rect.getLineD(line);
75+
76+
path.push(line.x2, line.y2);
77+
78+
this.pathData = path;
79+
80+
return this;
4881
}
4982

5083
});

src/gameobjects/shape/triangle/Triangle.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ var Triangle = new Class({
3434

3535
function Triangle (scene, x, y, x1, y1, x2, y2, x3, y3, fillColor, fillAlpha)
3636
{
37+
if (x === undefined) { x = 0; }
38+
if (y === undefined) { y = 0; }
39+
if (x1 === undefined) { x1 = 0; }
40+
if (y1 === undefined) { y1 = 128; }
41+
if (x2 === undefined) { x2 = 64; }
42+
if (y2 === undefined) { y2 = 0; }
43+
if (x3 === undefined) { x3 = 128; }
44+
if (y3 === undefined) { y3 = 128; }
45+
3746
Shape.call(this, scene, 'Triangle', new GeomTriangle(x1, y1, x2, y2, x3, y3));
3847

3948
var width = this.data.right - this.data.left;
@@ -42,12 +51,36 @@ var Triangle = new Class({
4251
this.setPosition(x, y);
4352
this.setSize(width, height);
4453

45-
this.updateDisplayOrigin();
46-
4754
if (fillColor !== undefined)
4855
{
4956
this.setFillStyle(fillColor, fillAlpha);
5057
}
58+
59+
this.updateDisplayOrigin();
60+
this.updateData();
61+
},
62+
63+
updateData: function ()
64+
{
65+
var path = [];
66+
var rect = this.data;
67+
var line = this._tempLine;
68+
69+
rect.getLineA(line);
70+
71+
path.push(line.x1, line.y1, line.x2, line.y2);
72+
73+
rect.getLineB(line);
74+
75+
path.push(line.x2, line.y2);
76+
77+
rect.getLineC(line);
78+
79+
path.push(line.x2, line.y2);
80+
81+
this.pathData = path;
82+
83+
return this;
5184
}
5285

5386
});

0 commit comments

Comments
 (0)