Skip to content

Commit 18fa629

Browse files
committed
Graphics objects now just take a config object, not a position.
Graphics objects can set default stroke and fill styles, which are re-applied after a clear.
1 parent b3b495e commit 18fa629

3 files changed

Lines changed: 61 additions & 8 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '5d589820-1417-11e7-a4fb-712e101ac5d8'
2+
build: '02229ca0-1488-11e7-8e2a-13177b968951'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/graphics/Graphics.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Components = require('../../components');
44
var Render = require('./GraphicsRender');
55
var Commands = require('./Commands');
66
var MATH_CONST = require('../../math/const');
7+
var GetObjectValue = require('../../utils/object/GetObjectValue');
78

89
var Graphics = new Class({
910

@@ -18,14 +19,48 @@ var Graphics = new Class({
1819

1920
initialize:
2021

21-
function Graphics (state, x, y)
22+
function Graphics (state, options)
2223
{
24+
var x = GetObjectValue(options, 'x', 0);
25+
var y = GetObjectValue(options, 'y', 0);
26+
2327
GameObject.call(this, state);
2428

2529
this.setPosition(x, y);
2630

2731
this.commandBuffer = [];
2832
this.initRenderPassComponent();
33+
34+
this.defaultFillColor = -1;
35+
this.defaultFillAlpha = 1;
36+
37+
this.defaultStrokeWidth = 1;
38+
this.defaultStrokeColor = -1;
39+
this.defaultStrokeAlpha = 1;
40+
41+
this.setDefaultStyles(options);
42+
},
43+
44+
setDefaultStyles: function (options)
45+
{
46+
if (GetObjectValue(options, 'lineStyle', null))
47+
{
48+
this.defaultStrokeWidth = GetObjectValue(options, 'lineStyle.width', 1);
49+
this.defaultStrokeColor = GetObjectValue(options, 'lineStyle.color', 0xffffff);
50+
this.defaultStrokeAlpha = GetObjectValue(options, 'lineStyle.alpha', 1);
51+
52+
this.lineStyle(this.defaultStrokeWidth, this.defaultStrokeColor, this.defaultStrokeAlpha);
53+
}
54+
55+
if (GetObjectValue(options, 'fillStyle', null))
56+
{
57+
this.defaultFillColor = GetObjectValue(options, 'fillStyle.color', 0xffffff);
58+
this.defaultFillAlpha = GetObjectValue(options, 'fillStyle.alpha', 1);
59+
60+
this.fillStyle(this.defaultFillColor, this.defaultFillAlpha);
61+
}
62+
63+
return this;
2964
},
3065

3166
arc: function (x, y, radius, startAngle, endAngle, anticlockwise)
@@ -96,6 +131,16 @@ var Graphics = new Class({
96131
return this;
97132
},
98133

134+
strokeShape: function (shape)
135+
{
136+
137+
},
138+
139+
fillShape: function (shape)
140+
{
141+
142+
},
143+
99144
fillCircle: function (x, y, radius)
100145
{
101146
this.beginPath();
@@ -204,6 +249,16 @@ var Graphics = new Class({
204249
{
205250
this.commandBuffer.length = 0;
206251

252+
if (this.defaultFillColor > -1)
253+
{
254+
this.fillStyle(this.defaultFillColor, this.defaultFillAlpha);
255+
}
256+
257+
if (this.defaultStrokeColor > -1)
258+
{
259+
this.lineStyle(this.defaultStrokeWidth, this.defaultStrokeColor, this.defaultStrokeAlpha);
260+
}
261+
207262
return this;
208263
}
209264

v3/src/gameobjects/graphics/GraphicsFactory.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ var GraphicsFactory = {
55

66
KEY: 'graphics',
77

8-
add: function (x, y, group)
8+
add: function (options)
99
{
10-
if (group === undefined) { group = this.state; }
11-
12-
return group.children.add(new Graphics(this.state, x, y));
10+
return this.state.children.add(new Graphics(this.state, options));
1311
},
1412

15-
make: function (x, y)
13+
make: function (options)
1614
{
17-
return new Graphics(this.state, x, y);
15+
return new Graphics(this.state, options);
1816
}
1917

2018
};

0 commit comments

Comments
 (0)