1+ var CONST = require ( '../../const' ) ;
12var DrawImage = require ( './utils/DrawImage' ) ;
3+ var GetBlendModes = require ( './utils/GetBlendModes' ) ;
24
35var CanvasRenderer = function ( game )
46{
@@ -8,7 +10,8 @@ var CanvasRenderer = function (game)
810 // Needed?
911 this . game = game ;
1012
11- // this.type = CONST.CANVAS;
13+ // Needed?
14+ this . type = CONST . CANVAS ;
1215
1316 // Read all the following from game config
1417 this . clearBeforeRender = true ;
@@ -41,9 +44,7 @@ var CanvasRenderer = function (game)
4144 // Map to the required function
4245 this . drawImage = DrawImage ;
4346
44- var so = 'source-over' ;
45-
46- this . blendModes = [ so , 'lighter' , so , so , so , so , so , so , so , so , so , so , so , so , so , so , so ] ;
47+ this . blendModes = GetBlendModes ( ) ;
4748
4849 this . currentAlpha = 1 ;
4950 this . currentBlendMode = 0 ;
@@ -64,38 +65,9 @@ CanvasRenderer.prototype = {
6465
6566 init : function ( )
6667 {
67- this . mapBlendModes ( ) ;
68-
6968 this . resize ( this . width , this . height ) ;
7069 } ,
7170
72- /**
73- * Maps Blend modes to Canvas blend modes.
74- *
75- * @method mapBlendModes
76- * @private
77- */
78- mapBlendModes : function ( )
79- {
80- // var modes = Phaser.blendModes;
81-
82- // this.blendModes[modes.MULTIPLY] = 'multiply';
83- // this.blendModes[modes.SCREEN] = 'screen';
84- // this.blendModes[modes.OVERLAY] = 'overlay';
85- // this.blendModes[modes.DARKEN] = 'darken';
86- // this.blendModes[modes.LIGHTEN] = 'lighten';
87- // this.blendModes[modes.COLOR_DODGE] = 'color-dodge';
88- // this.blendModes[modes.COLOR_BURN] = 'color-burn';
89- // this.blendModes[modes.HARD_LIGHT] = 'hard-light';
90- // this.blendModes[modes.SOFT_LIGHT] = 'soft-light';
91- // this.blendModes[modes.DIFFERENCE] = 'difference';
92- // this.blendModes[modes.EXCLUSION] = 'exclusion';
93- // this.blendModes[modes.HUE] = 'hue';
94- // this.blendModes[modes.SATURATION] = 'saturation';
95- // this.blendModes[modes.COLOR] = 'color';
96- // this.blendModes[modes.LUMINOSITY] = 'luminosity';
97- } ,
98-
9971 resize : function ( width , height )
10072 {
10173 var res = this . game . config . resolution ;
@@ -131,24 +103,26 @@ CanvasRenderer.prototype = {
131103 {
132104 // console.log('%c render start ', 'color: #ffffff; background: #00ff00;');
133105
106+ var ctx = this . context ;
107+
134108 // Add Pre-render hook
135109
136110 // TODO: A State should have the option of having its own canvas to draw to
137111
138112 this . startTime = Date . now ( ) ;
139113
140- this . context . setTransform ( 1 , 0 , 0 , 1 , 0 , 0 ) ;
114+ ctx . setTransform ( 1 , 0 , 0 , 1 , 0 , 0 ) ;
141115
142116 // If the alpha or blend mode didn't change since the last render, then don't set them again (saves 2 ops)
143117
144118 if ( this . currentAlpha !== 1 )
145119 {
146- this . context . globalAlpha = 1 ;
120+ ctx . globalAlpha = 1 ;
147121 }
148122
149123 if ( this . currentBlendMode !== 0 )
150124 {
151- this . context . globalCompositeOperation = 'source-over' ;
125+ ctx . globalCompositeOperation = 'source-over' ;
152126 }
153127
154128 this . currentBlendMode = 0 ;
@@ -157,7 +131,7 @@ CanvasRenderer.prototype = {
157131
158132 if ( this . clearBeforeRender )
159133 {
160- this . context . clearRect ( 0 , 0 , this . width , this . height ) ;
134+ ctx . clearRect ( 0 , 0 , this . width , this . height ) ;
161135 }
162136
163137 this . drawCount = 0 ;
0 commit comments