@@ -6,28 +6,115 @@ var Color = new Class({
66
77 initialize :
88
9+ /**
10+ * The Color class holds a single color value and allows for easy modification and reading of it.
11+ *
12+ * @class Color
13+ * @memberOf Phaser.Display
14+ * @constructor
15+ * @since 3.0.0
16+ *
17+ * @param {integer } [red=0] - The red color value. A number between 0 and 255.
18+ * @param {integer } [green=0] - The green color value. A number between 0 and 255.
19+ * @param {integer } [blue=0] - The blue color value. A number between 0 and 255.
20+ * @param {integer } [alpha=255] - The alpha value. A number between 0 and 255.
21+ */
922 function Color ( red , green , blue , alpha )
1023 {
1124 if ( red === undefined ) { red = 0 ; }
1225 if ( green === undefined ) { green = 0 ; }
1326 if ( blue === undefined ) { blue = 0 ; }
1427 if ( alpha === undefined ) { alpha = 255 ; }
1528
16- // All private
29+ /**
30+ * The internal red color value.
31+ *
32+ * @property {number } r
33+ * @private
34+ * @default 0
35+ * @since 3.0.0
36+ */
1737 this . r = 0 ;
38+
39+ /**
40+ * The internal green color value.
41+ *
42+ * @property {number } g
43+ * @private
44+ * @default 0
45+ * @since 3.0.0
46+ */
1847 this . g = 0 ;
48+
49+ /**
50+ * The internal blue color value.
51+ *
52+ * @property {number } b
53+ * @private
54+ * @default 0
55+ * @since 3.0.0
56+ */
1957 this . b = 0 ;
20- this . a = 255 ;
2158
22- this . gl = [ 0.0 , 0.0 , 0.0 , 1.0 ] ;
59+ /**
60+ * The internal alpha color value.
61+ *
62+ * @property {number } a
63+ * @private
64+ * @default 255
65+ * @since 3.0.0
66+ */
67+ this . a = 255 ;
2368
69+ /**
70+ * An array containing the calculated color values for WebGL use.
71+ *
72+ * @property {array } gl
73+ * @since 3.0.0
74+ */
75+ this . gl = [ 0 , 0 , 0 , 1 ] ;
76+
77+ /**
78+ * Pre-calculated internal color value.
79+ *
80+ * @property {number } _color
81+ * @private
82+ * @default 0
83+ * @since 3.0.0
84+ */
2485 this . _color = 0 ;
86+
87+ /**
88+ * Pre-calculated internal color32 value.
89+ *
90+ * @property {number } _color32
91+ * @private
92+ * @default 0
93+ * @since 3.0.0
94+ */
2595 this . _color32 = 0 ;
96+
97+ /**
98+ * Pre-calculated internal color rgb string value.
99+ *
100+ * @property {string } _rgba
101+ * @private
102+ * @default ''
103+ * @since 3.0.0
104+ */
26105 this . _rgba = '' ;
27106
28107 this . setTo ( red , green , blue , alpha ) ;
29108 } ,
30109
110+ /**
111+ * Sets this color to be transparent. Sets all values to zero.
112+ *
113+ * @method Phaser.Curves.Color#transparent
114+ * @since 3.0.0
115+ *
116+ * @return {Phaser.Display.Color } This Color object.
117+ */
31118 transparent : function ( )
32119 {
33120 this . red = 0 ;
@@ -38,7 +125,19 @@ var Color = new Class({
38125 return this . update ( ) ;
39126 } ,
40127
41- // Values are in the range 0 to 255
128+ /**
129+ * Sets the color of this Color component.
130+ *
131+ * @method Phaser.Curves.Color#setTo
132+ * @since 3.0.0
133+ *
134+ * @param {integer } red - The red color value. A number between 0 and 255.
135+ * @param {integer } green - The green color value. A number between 0 and 255.
136+ * @param {integer } blue - The blue color value. A number between 0 and 255.
137+ * @param {integer } [alpha=255] - The alpha value. A number between 0 and 255.
138+ *
139+ * @return {Phaser.Display.Color } This Color object.
140+ */
42141 setTo : function ( red , green , blue , alpha )
43142 {
44143 if ( alpha === undefined ) { alpha = 255 ; }
@@ -51,7 +150,19 @@ var Color = new Class({
51150 return this . update ( ) ;
52151 } ,
53152
54- // Values are in the range 0 to 1
153+ /**
154+ * Sets the red, green, blue and alpha GL values of this Color component.
155+ *
156+ * @method Phaser.Curves.Color#setGLTo
157+ * @since 3.0.0
158+ *
159+ * @param {float } red - The red color value. A number between 0 and 1.
160+ * @param {float } green - The green color value. A number between 0 and 1.
161+ * @param {float } blue - The blue color value. A number between 0 and 1.
162+ * @param {float } [alpha=1] - The alpha value. A number between 0 and 1.
163+ *
164+ * @return {Phaser.Display.Color } This Color object.
165+ */
55166 setGLTo : function ( red , green , blue , alpha )
56167 {
57168 if ( alpha === undefined ) { alpha = 1 ; }
@@ -64,6 +175,16 @@ var Color = new Class({
64175 return this . update ( ) ;
65176 } ,
66177
178+ /**
179+ * Sets the color based on the color object given.
180+ *
181+ * @method Phaser.Curves.Color#setFromRGB
182+ * @since 3.0.0
183+ *
184+ * @param {object } color - An object containing `r`, `g`, `b` and optionally `a` values in the range 0 to 255.
185+ *
186+ * @return {Phaser.Display.Color } This Color object.
187+ */
67188 setFromRGB : function ( color )
68189 {
69190 this . red = color . r ;
@@ -78,6 +199,14 @@ var Color = new Class({
78199 return this . update ( ) ;
79200 } ,
80201
202+ /**
203+ * Updates the internal cache values.
204+ *
205+ * @method Phaser.Curves.Color#update
206+ * @since 3.0.0
207+ *
208+ * @return {Phaser.Display.Color } This Color object.
209+ */
81210 update : function ( )
82211 {
83212 this . _color = GetColor ( this . r , this . g , this . b ) ;
@@ -87,12 +216,27 @@ var Color = new Class({
87216 return this ;
88217 } ,
89218
90- // Same as setRGB but performs safety checks on all the values given
219+ /**
220+ * Returns a new Color component using the values from this one.
221+ *
222+ * @method Phaser.Curves.Color#clone
223+ * @since 3.0.0
224+ *
225+ * @return {Phaser.Display.Color } A new Color object.
226+ */
91227 clone : function ( )
92228 {
93229 return new Color ( this . r , this . g , this . b , this . a ) ;
94230 } ,
95231
232+ /**
233+ * The color of this Color component, not including the alpha channel.
234+ *
235+ * @name Phaser.Display.Color#color
236+ * @property {number } color
237+ * @readOnly
238+ * @since 3.0.0
239+ */
96240 color : {
97241
98242 get : function ( )
@@ -102,6 +246,14 @@ var Color = new Class({
102246
103247 } ,
104248
249+ /**
250+ * The color of this Color component, including the alpha channel.
251+ *
252+ * @name Phaser.Display.Color#color32
253+ * @property {number } color32
254+ * @readOnly
255+ * @since 3.0.0
256+ */
105257 color32 : {
106258
107259 get : function ( )
@@ -111,6 +263,14 @@ var Color = new Class({
111263
112264 } ,
113265
266+ /**
267+ * The color of this Color component as a string which can be used in CSS color values.
268+ *
269+ * @name Phaser.Display.Color#rgba
270+ * @property {string } rgba
271+ * @readOnly
272+ * @since 3.0.0
273+ */
114274 rgba : {
115275
116276 get : function ( )
@@ -120,7 +280,13 @@ var Color = new Class({
120280
121281 } ,
122282
123- // Gets and sets the red value, normalized to the 0 to 1 range
283+ /**
284+ * The red color value, normalized to the range 0 to 1.
285+ *
286+ * @name Phaser.Display.Color#redGL
287+ * @property {float } redGL
288+ * @since 3.0.0
289+ */
124290 redGL : {
125291
126292 get : function ( )
@@ -139,6 +305,13 @@ var Color = new Class({
139305
140306 } ,
141307
308+ /**
309+ * The green color value, normalized to the range 0 to 1.
310+ *
311+ * @name Phaser.Display.Color#greenGL
312+ * @property {float } greenGL
313+ * @since 3.0.0
314+ */
142315 greenGL : {
143316
144317 get : function ( )
@@ -157,6 +330,13 @@ var Color = new Class({
157330
158331 } ,
159332
333+ /**
334+ * The blue color value, normalized to the range 0 to 1.
335+ *
336+ * @name Phaser.Display.Color#blueGL
337+ * @property {float } blueGL
338+ * @since 3.0.0
339+ */
160340 blueGL : {
161341
162342 get : function ( )
@@ -175,6 +355,13 @@ var Color = new Class({
175355
176356 } ,
177357
358+ /**
359+ * The alpha color value, normalized to the range 0 to 1.
360+ *
361+ * @name Phaser.Display.Color#alphaGL
362+ * @property {float } alphaGL
363+ * @since 3.0.0
364+ */
178365 alphaGL : {
179366
180367 get : function ( )
@@ -193,7 +380,13 @@ var Color = new Class({
193380
194381 } ,
195382
196- // Gets and sets the red value, normalized to the 0 to 255 range
383+ /**
384+ * The red color value, normalized to the range 0 to 255.
385+ *
386+ * @name Phaser.Display.Color#red
387+ * @property {float } red
388+ * @since 3.0.0
389+ */
197390 red : {
198391
199392 get : function ( )
@@ -214,6 +407,13 @@ var Color = new Class({
214407
215408 } ,
216409
410+ /**
411+ * The green color value, normalized to the range 0 to 255.
412+ *
413+ * @name Phaser.Display.Color#green
414+ * @property {float } green
415+ * @since 3.0.0
416+ */
217417 green : {
218418
219419 get : function ( )
@@ -234,6 +434,13 @@ var Color = new Class({
234434
235435 } ,
236436
437+ /**
438+ * The blue color value, normalized to the range 0 to 255.
439+ *
440+ * @name Phaser.Display.Color#blue
441+ * @property {float } blue
442+ * @since 3.0.0
443+ */
237444 blue : {
238445
239446 get : function ( )
@@ -254,6 +461,13 @@ var Color = new Class({
254461
255462 } ,
256463
464+ /**
465+ * The alpha color value, normalized to the range 0 to 255.
466+ *
467+ * @name Phaser.Display.Color#alpha
468+ * @property {float } alpha
469+ * @since 3.0.0
470+ */
257471 alpha : {
258472
259473 get : function ( )
0 commit comments