forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitmapData.js.html
1613 lines (1250 loc) · 47.4 KB
/
BitmapData.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Phaser Source: gameobjects/BitmapData.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
</head>
<body>
<div class="container-fluid">
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<a class="brand" href="index.html">Phaser</a>
<ul class="nav">
<li class="dropdown">
<a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="Phaser.html">Phaser</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="Phaser.Animation.html">Animation</a>
</li>
<li>
<a href="Phaser.AnimationManager.html">AnimationManager</a>
</li>
<li>
<a href="Phaser.AnimationParser.html">AnimationParser</a>
</li>
<li>
<a href="Phaser.BitmapData.html">BitmapData</a>
</li>
<li>
<a href="Phaser.BitmapText.html">BitmapText</a>
</li>
<li>
<a href="Phaser.Button.html">Button</a>
</li>
<li>
<a href="Phaser.Cache.html">Cache</a>
</li>
<li>
<a href="Phaser.Camera.html">Camera</a>
</li>
<li>
<a href="Phaser.Canvas.html">Canvas</a>
</li>
<li>
<a href="Phaser.Circle.html">Circle</a>
</li>
<li>
<a href="Phaser.Color.html">Color</a>
</li>
<li>
<a href="Phaser.Device.html">Device</a>
</li>
<li>
<a href="Phaser.DOMSprite.html">DOMSprite</a>
</li>
<li>
<a href="Phaser.Easing.html">Easing</a>
</li>
<li>
<a href="Phaser.Easing.Back.html">Back</a>
</li>
<li>
<a href="Phaser.Easing.Bounce.html">Bounce</a>
</li>
<li>
<a href="Phaser.Easing.Circular.html">Circular</a>
</li>
<li>
<a href="Phaser.Easing.Cubic.html">Cubic</a>
</li>
<li>
<a href="Phaser.Easing.Elastic.html">Elastic</a>
</li>
<li>
<a href="Phaser.Easing.Exponential.html">Exponential</a>
</li>
<li>
<a href="Phaser.Easing.Linear.html">Linear</a>
</li>
<li>
<a href="Phaser.Easing.Quadratic.html">Quadratic</a>
</li>
<li>
<a href="Phaser.Easing.Quartic.html">Quartic</a>
</li>
<li>
<a href="Phaser.Easing.Quintic.html">Quintic</a>
</li>
<li>
<a href="Phaser.Easing.Sinusoidal.html">Sinusoidal</a>
</li>
<li>
<a href="Phaser.Events.html">Events</a>
</li>
<li>
<a href="Phaser.Filter.html">Filter</a>
</li>
<li>
<a href="Phaser.Frame.html">Frame</a>
</li>
<li>
<a href="Phaser.FrameData.html">FrameData</a>
</li>
<li>
<a href="Phaser.Game.html">Game</a>
</li>
<li>
<a href="Phaser.GameObjectFactory.html">GameObjectFactory</a>
</li>
<li>
<a href="Phaser.Gamepad.html">Gamepad</a>
</li>
<li>
<a href="Phaser.GamepadButton.html">GamepadButton</a>
</li>
<li>
<a href="Phaser.Graphics.html">Graphics</a>
</li>
<li>
<a href="Phaser.Group.html">Group</a>
</li>
<li>
<a href="Phaser.Input.html">Input</a>
</li>
<li>
<a href="Phaser.InputHandler.html">InputHandler</a>
</li>
<li>
<a href="Phaser.Key.html">Key</a>
</li>
<li>
<a href="Phaser.Keyboard.html">Keyboard</a>
</li>
<li>
<a href="Phaser.Line.html">Line</a>
</li>
<li>
<a href="Phaser.LinkedList.html">LinkedList</a>
</li>
<li>
<a href="Phaser.Loader.html">Loader</a>
</li>
<li>
<a href="Phaser.LoaderParser.html">LoaderParser</a>
</li>
<li>
<a href="Phaser.Math.html">Math</a>
</li>
<li>
<a href="Phaser.Mouse.html">Mouse</a>
</li>
<li>
<a href="Phaser.MSPointer.html">MSPointer</a>
</li>
<li>
<a href="Phaser.Net.html">Net</a>
</li>
<li>
<a href="Phaser.Particles.html">Particles</a>
</li>
<li>
<a href="Phaser.Particles.Arcade.Emitter.html">Emitter</a>
</li>
<li>
<a href="Phaser.Physics.html">Physics</a>
</li>
<li>
<a href="Phaser.Physics.Arcade.html">Arcade</a>
</li>
<li>
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
</li>
<li>
<a href="Phaser.Plugin.html">Plugin</a>
</li>
<li>
<a href="Phaser.PluginManager.html">PluginManager</a>
</li>
<li>
<a href="Phaser.Point.html">Point</a>
</li>
<li>
<a href="Phaser.Pointer.html">Pointer</a>
</li>
<li>
<a href="Phaser.Polygon.html">Polygon</a>
</li>
<li>
<a href="Phaser.QuadTree.html">QuadTree</a>
</li>
<li>
<a href="Phaser.RandomDataGenerator.html">RandomDataGenerator</a>
</li>
<li>
<a href="Phaser.Rectangle.html">Rectangle</a>
</li>
<li>
<a href="Phaser.RenderTexture.html">RenderTexture</a>
</li>
<li>
<a href="Phaser.RequestAnimationFrame.html">RequestAnimationFrame</a>
</li>
<li>
<a href="Phaser.Signal.html">Signal</a>
</li>
<li>
<a href="Phaser.SinglePad.html">SinglePad</a>
</li>
<li>
<a href="Phaser.Sound.html">Sound</a>
</li>
<li>
<a href="Phaser.SoundManager.html">SoundManager</a>
</li>
<li>
<a href="Phaser.Sprite.html">Sprite</a>
</li>
<li>
<a href="Phaser.Stage.html">Stage</a>
</li>
<li>
<a href="Phaser.StageScaleMode.html">StageScaleMode</a>
</li>
<li>
<a href="Phaser.State.html">State</a>
</li>
<li>
<a href="Phaser.StateManager.html">StateManager</a>
</li>
<li>
<a href="Phaser.Text.html">Text</a>
</li>
<li>
<a href="Phaser.Tile.html">Tile</a>
</li>
<li>
<a href="Phaser.Tilemap.html">Tilemap</a>
</li>
<li>
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
</li>
<li>
<a href="Phaser.TilemapParser.html">TilemapParser</a>
</li>
<li>
<a href="Phaser.Tileset.html">Tileset</a>
</li>
<li>
<a href="Phaser.TileSprite.html">TileSprite</a>
</li>
<li>
<a href="Phaser.Time.html">Time</a>
</li>
<li>
<a href="Phaser.Timer.html">Timer</a>
</li>
<li>
<a href="Phaser.TimerEvent.html">TimerEvent</a>
</li>
<li>
<a href="Phaser.Touch.html">Touch</a>
</li>
<li>
<a href="Phaser.Tween.html">Tween</a>
</li>
<li>
<a href="Phaser.TweenManager.html">TweenManager</a>
</li>
<li>
<a href="Phaser.Utils.html">Utils</a>
</li>
<li>
<a href="Phaser.Utils.Debug.html">Debug</a>
</li>
<li>
<a href="Phaser.World.html">World</a>
</li>
<li>
<a href="SignalBinding.html">SignalBinding</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="global.html#SAT">SAT</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div id="main">
<h1 class="page-title">Source: gameobjects/BitmapData.js</h1>
<section>
<article>
<pre class="sunlight-highlight-javascript linenums">/**
* @author Richard Davey <[email protected]>
* @copyright 2014 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Creates a new BitmapData object.
*
* @class Phaser.BitmapData
*
* @classdesc Note: This object is still experimental and likely to change.
*
* A BitmapData object can be thought of as a blank canvas onto which you can perform graphics operations as you would on a normal canvas,
* such as drawing lines, circles, arcs, fills and copying and setting blocks of pixel data. A single BitmapData can be used as the texture
* for multiple Sprites. So if you need to dynamically create a Sprite texture then they are a good choice. It supports the EaselJS Tiny API.
*
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {number} [width=256] - The width of the BitmapData in pixels.
* @param {number} [height=256] - The height of the BitmapData in pixels.
*/
Phaser.BitmapData = function (game, width, height) {
if (typeof width === 'undefined') { width = 256; }
if (typeof height === 'undefined') { height = 256; }
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {string} name - The name of the BitmapData.
*/
this.name = '';
/**
* @property {number} width - The width of the BitmapData in pixels.
*/
this.width = width;
/**
* @property {number} height - The height of the BitmapData in pixels.
*/
this.height = height;
/**
* @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws.
* @default
*/
this.canvas = Phaser.Canvas.create(width, height);
/**
* @property {CanvasRenderingContext2D} context - The 2d context of the canvas.
* @default
*/
this.context = this.canvas.getContext('2d');
/**
* @property {array} imageData - The canvas image data.
*/
this.imageData = this.context.getImageData(0, 0, width, height);
/**
* @property {UInt8Clamped} pixels - A reference to the context imageData buffer.
*/
if (this.imageData.data.buffer)
{
this.pixels = this.imageData.data.buffer;
}
else
{
this.pixels = this.imageData.data;
}
/**
* @property {PIXI.BaseTexture} baseTexture - The PIXI.BaseTexture.
* @default
*/
this.baseTexture = new PIXI.BaseTexture(this.canvas);
/**
* @property {PIXI.Texture} texture - The PIXI.Texture.
* @default
*/
this.texture = new PIXI.Texture(this.baseTexture);
/**
* @property {Phaser.Frame} textureFrame - The Frame this BitmapData uses for rendering.
* @default
*/
this.textureFrame = new Phaser.Frame(0, 0, 0, width, height, 'bitmapData', game.rnd.uuid());
/**
* @property {number} type - The const type of this object.
* @default
*/
this.type = Phaser.BITMAPDATA;
this._dirty = false;
}
Phaser.BitmapData.prototype = {
/**
* Updates the given Sprite so that it uses this BitmapData as its texture.
* @method Phaser.BitmapData#add
* @param {Phaser.Sprite} sprite - The sprite to apply this texture to.
*/
add: function (sprite) {
sprite.loadTexture(this);
},
/**
* Given an array of Sprites it will update each of them so that their Textures reference this BitmapData.
* @method Phaser.BitmapData#addTo
* @param {Phaser.Sprite[]} sprites - An array of Sprites to apply this texture to.
*/
addTo: function (sprites) {
for (var i = 0; i < sprites.length; i++)
{
if (sprites[i].texture)
{
sprites[i].loadTexture(this);
}
}
},
/**
* Clears the BitmapData.
* @method Phaser.BitmapData#clear
*/
clear: function () {
this.context.clearRect(0, 0, this.width, this.height);
this._dirty = true;
},
refreshBuffer: function () {
this.imageData = this.context.getImageData(0, 0, this.width, this.height);
this.pixels = new Int32Array(this.imageData.data.buffer);
// this.data8 = new Uint8ClampedArray(this.imageData.buffer);
// this.data32 = new Uint32Array(this.imageData.buffer);
},
/**
* Sets the color of the given pixel to the specified red, green, blue and alpha values.
* @method Phaser.BitmapData#setPixel32
* @param {number} x - The X coordinate of the pixel to be set.
* @param {number} y - The Y coordinate of the pixel to be set.
* @param {number} red - The red color value, between 0 and 0xFF (255).
* @param {number} green - The green color value, between 0 and 0xFF (255).
* @param {number} blue - The blue color value, between 0 and 0xFF (255).
* @param {number} alpha - The alpha color value, between 0 and 0xFF (255).
*/
setPixel32: function (x, y, red, green, blue, alpha) {
if (x >= 0 && x <= this.width && y >= 0 && y <= this.height)
{
this.pixels[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red;
/*
if (this.isLittleEndian)
{
this.data32[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red;
}
else
{
this.data32[y * this.width + x] = (red << 24) | (green << 16) | (blue << 8) | alpha;
}
*/
// this.imageData.data.set(this.data8);
this.context.putImageData(this.imageData, 0, 0);
this._dirty = true;
}
},
/**
* Sets the color of the given pixel to the specified red, green and blue values.
* @method Phaser.BitmapData#setPixel
* @param {number} x - The X coordinate of the pixel to be set.
* @param {number} y - The Y coordinate of the pixel to be set.
* @param {number} red - The red color value (between 0 and 255)
* @param {number} green - The green color value (between 0 and 255)
* @param {number} blue - The blue color value (between 0 and 255)
*/
setPixel: function (x, y, red, green, blue) {
this.setPixel32(x, y, red, green, blue, 255);
},
/**
* Get a color of a specific pixel.
* @param {number} x - The X coordinate of the pixel to get.
* @param {number} y - The Y coordinate of the pixel to get.
* @return {number} A native color value integer (format: 0xRRGGBB)
*/
getPixel: function (x, y) {
if (x >= 0 && x <= this.width && y >= 0 && y <= this.height)
{
return this.data32[y * this.width + x];
}
},
/**
* Get a color of a specific pixel (including alpha value).
* @param {number} x - The X coordinate of the pixel to get.
* @param {number} y - The Y coordinate of the pixel to get.
* @return {number} A native color value integer (format: 0xAARRGGBB)
*/
getPixel32: function (x, y) {
if (x >= 0 && x <= this.width && y >= 0 && y <= this.height)
{
return this.data32[y * this.width + x];
}
},
/**
* Get pixels in array in a specific Rectangle.
* @param rect {Rectangle} The specific Rectangle.
* @return {array} CanvasPixelArray.
*/
getPixels: function (rect) {
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
},
/**
* Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at endAngle
* going in the given direction by anticlockwise (defaulting to clockwise).
* @method Phaser.BitmapData#arc
* @param {number} x - The x axis of the coordinate for the arc's center
* @param {number} y - The y axis of the coordinate for the arc's center
* @param {number} radius - The arc's radius
* @param {number} startAngle - The starting point, measured from the x axis, from which it will be drawn, expressed in radians.
* @param {number} endAngle - The end arc's angle to which it will be drawn, expressed in radians.
* @param {boolean} [anticlockwise=true] - true draws the arc anticlockwise, otherwise in a clockwise direction.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
arc: function (x, y, radius, startAngle, endAngle, anticlockwise) {
if (typeof anticlockwise === 'undefined') { anticlockwise = false; }
this._dirty = true;
this.context.arc(x, y, radius, startAngle, endAngle, anticlockwise);
return this;
},
/**
* Adds an arc with the given control points and radius, connected to the previous point by a straight line.
* @method Phaser.BitmapData#arcTo
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @param {number} radius
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
arcTo: function (x1, y1, x2, y2, radius) {
this._dirty = true;
this.context.arcTo(x1, y1, x2, y2, radius);
return this;
},
/**
* Begins a fill with the specified color. This ends the current sub-path.
* @method Phaser.BitmapData#beginFill
* @param {string} color - A CSS compatible color value (ex. "red", "#FF0000", or "rgba(255,0,0,0.5)"). Setting to null will result in no fill.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
beginFill: function (color) {
this.fillStyle(color);
return this;
},
/**
* Begins a linear gradient fill defined by the line (x0, y0) to (x1, y1). This ends the current sub-path. For
* example, the following code defines a black to white vertical gradient ranging from 20px to 120px, and draws a square to display it:
*
* ```myGraphics.beginLinearGradientFill(["#000","#FFF"], [0, 1], 0, 20, 0, 120).rect(20, 20, 120, 120);```
*
* @method Phaser.BitmapData#beginLinearGradientFill
* @param {Array} colors - An array of CSS compatible color values. For example, ["#F00","#00F"] would define a gradient drawing from red to blue.
* @param {Array} ratios - An array of gradient positions which correspond to the colors. For example, [0.1, 0.9] would draw the first color to 10% then interpolating to the second color at 90%.
* @param {number} x0 - The position of the first point defining the line that defines the gradient direction and size.
* @param {number} y0 - The position of the first point defining the line that defines the gradient direction and size.
* @param {number} x1 - The position of the second point defining the line that defines the gradient direction and size.
* @param {number} y1 - The position of the second point defining the line that defines the gradient direction and size.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
beginLinearGradientFill: function (colors, ratios, x0, y0, x1, y1) {
var gradient = this.createLinearGradient(x0, y0, x1, y1);
for (var i = 0, len = colors.length; i < len; i++)
{
gradient.addColorStop(ratios[i], colors[i]);
}
this.fillStyle(gradient);
return this;
},
/**
* Begins a linear gradient stroke defined by the line (x0, y0) to (x1, y1). This ends the current sub-path. For
* example, the following code defines a black to white vertical gradient ranging from 20px to 120px, and draws a
* square to display it:
*
* ```myGraphics.setStrokeStyle(10).beginLinearGradientStroke(["#000","#FFF"], [0, 1], 0, 20, 0, 120).drawRect(20, 20, 120, 120);```
*
* @method Phaser.BitmapData#beginLinearGradientStroke
* @param {Array} colors - An array of CSS compatible color values. For example, ["#F00","#00F"] would define a gradient drawing from red to blue.
* @param {Array} ratios - An array of gradient positions which correspond to the colors. For example, [0.1, 0.9] would draw the first color to 10% then interpolating to the second color at 90%.
* @param {number} x0 - The position of the first point defining the line that defines the gradient direction and size.
* @param {number} y0 - The position of the first point defining the line that defines the gradient direction and size.
* @param {number} x1 - The position of the second point defining the line that defines the gradient direction and size.
* @param {number} y1 - The position of the second point defining the line that defines the gradient direction and size.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
beginLinearGradientStroke: function (colors, ratios, x0, y0, x1, y1) {
var gradient = this.createLinearGradient(x0, y0, x1, y1);
for (var i = 0, len = colors.length; i < len; i++)
{
gradient.addColorStop(ratios[i], colors[i]);
}
this.strokeStyle(gradient);
return this;
},
/**
* Begins a radial gradient stroke. This ends the current sub-path. For example, the following code defines a red to
* blue radial gradient centered at (100, 100), with a radius of 50, and draws a rectangle to display it:
*
* myGraphics.setStrokeStyle(10)
* .beginRadialGradientStroke(["#F00","#00F"], [0, 1], 100, 100, 0, 100, 100, 50)
* .drawRect(50, 90, 150, 110);
*
* @method Phaser.BitmapData#beginRadialGradientStroke
* @param {Array} colors - An array of CSS compatible color values. For example, ["#F00","#00F"] would define a gradient drawing from red to blue.
* @param {Array} ratios - An array of gradient positions which correspond to the colors. For example, [0.1, 0.9] would draw the first color to 10% then interpolating to the second color at 90%.
* @param {number} x0 - Center position of the inner circle that defines the gradient.
* @param {number} y0 - Center position of the inner circle that defines the gradient.
* @param {number} r0 - Radius of the inner circle that defines the gradient.
* @param {number} x1 - Center position of the outer circle that defines the gradient.
* @param {number} y1 - Center position of the outer circle that defines the gradient.
* @param {number} r1 - Radius of the outer circle that defines the gradient.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
beginRadialGradientStroke: function (colors, ratios, x0, y0, r0, x1, y1, r1) {
var gradient = this.createRadialGradient(x0, y0, r0, x1, y1, r1);
for (var i = 0, len = colors.length; i < len; i++)
{
gradient.addColorStop(ratios[i], colors[i]);
}
this.strokeStyle(gradient);
return this;
},
/**
* Starts a new path by resetting the list of sub-paths. Call this method when you want to create a new path.
* @method Phaser.BitmapData#beginPath
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
beginPath: function () {
this.context.beginPath();
return this;
},
/**
* Begins a stroke with the specified color. This ends the current sub-path.
* @method Phaser.BitmapData#beginStroke
* @param {String} color A CSS compatible color value (ex. "#FF0000", "red", or "rgba(255,0,0,0.5)"). Setting to null will result in no stroke.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
beginStroke: function (color) {
this.strokeStyle(color);
return this;
},
/**
* Adds a bezier curve from the current context point to (x, y) using the control points (cp1x, cp1y) and (cp2x, cp2y).
* @method Phaser.BitmapData#bezierCurveTo
* @param {number} cp1x - The x axis of control point 1.
* @param {number} cp1y - The y axis of control point 1.
* @param {number} cp2x - The x axis of control point 2.
* @param {number} cp2y - The y axis of control point 2.
* @param {number} x - The x axis of the ending point.
* @param {number} y - The y axis of the ending point.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
bezierCurveTo: function (cp1x, cp1y, cp2x, cp2y, x, y) {
this._dirty = true;
this.context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
return this;
},
/**
* Draws a circle with the specified radius at (x, y).
* @method Phaser.BitmapData#circle
* @param {number} x - x coordinate center point of circle.
* @param {number} y - y coordinate center point of circle.
* @param {number} radius - Radius of circle in radians.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
circle: function (x, y, radius) {
this.arc(x, y, radius, 0, Math.PI*2);
return this;
},
/**
* Sets all pixels in the rectangle defined by starting point (x, y) and size (width, height) to transparent black.
* @method Phaser.BitmapData#clearRect
* @param {number} x - The x axis of the coordinate for the rectangle starting point.
* @param {number} y - The y axis of the coordinate for the rectangle starting point.
* @param {number} width - The rectangles width.
* @param {number} height - The rectangles height.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
clearRect: function (x, y, width, height) {
this._dirty = true;
this.context.clearRect(x, y, width, height);
return this;
},
/**
* Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the clipping path only.
* @method Phaser.BitmapData#clip
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
clip: function () {
this._dirty = true;
this.context.clip();
return this;
},
/**
* Tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing.
* @method Phaser.BitmapData#closePath
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
closePath: function () {
this._dirty = true;
this.context.closePath();
return this;
},
/**
* Creates a linear gradient with defined by an imaginary line which implies the direction of the gradient.
* Once the gradient is created colors can be inserted using the addColorStop method.
* @method Phaser.BitmapData#createLinearGradient
* @param {number} x - The x axis of the coordinate for the gradients starting point.
* @param {number} y - The y axis of the coordinate for the gradients starting point.
* @param {number} width - The width of the gradient.
* @param {number} height - The height of the gradient.
* @return {CanvasGradient} The Linear Gradient.
*/
createLinearGradient: function (x, y, width, height) {
return this.context.createLinearGradient(x, y, width, height);
},
// createPattern
/**
* Creates a radial gradient.
* @method Phaser.BitmapData#createRadialGradient
* @param {number} x0
* @param {number} y0
* @param {number} r0
* @param {number} x1
* @param {number} y1
* @param {number} r1
* @return {CanvasGradient} The Radial Gradient.
*/
createRadialGradient: function (x0, y0, r0, x1, y1, r1) {
return this.context.createRadialGradient(x0, y0, r0, x1, y1, r1);
},
// drawImage
// drawSystemFocusRing (?)
/**
* Draws an ellipse (oval) with a specified width (w) and height (h).
* @method Phaser.BitmapData#ellipse
* @param {number} x - x coordinate center point of ellipse.
* @param {number} y - y coordinate center point of ellipse.
* @param {number} w - height (horizontal diameter) of ellipse. The horizontal radius will be half of this number.
* @param {number} h - width (vertical diameter) of ellipse. The vertical radius will be half of this number.
* @return {Phaser.BitmapData} The BitmapData instance this method was called on.
*/
ellipse: function (x, y, w, h) {
var k = 0.5522848;
var ox = (w / 2) * k;
var oy = (h / 2) * k;
var xe = x + w;
var ye = y + h;
var xm = x + w / 2;
var ym = y + h / 2;
this.moveTo(x, ym);
this.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
this.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
this.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
this.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
return this;
},
/**
* Fills the subpaths with the current fill style.
* @method Phaser.BitmapData#fill