@@ -33,6 +33,8 @@ Phaser.Renderer.Canvas = function (game)
3333 */
3434 this . clearBeforeRender = game . clearBeforeRender ;
3535
36+ this . dirtyRender = true ;
37+
3638 /**
3739 * Whether the render view is transparent
3840 *
@@ -80,7 +82,7 @@ Phaser.Renderer.Canvas = function (game)
8082 * @property context
8183 * @type CanvasRenderingContext2D
8284 */
83- this . context = this . view . getContext ( '2d' , { alpha : this . transparent } ) ;
85+ this . context = this . view . getContext ( '2d' , { alpha : true } ) ;
8486
8587 this . smoothProperty = Phaser . Canvas . getSmoothingPrefix ( this . context ) ;
8688
@@ -90,6 +92,7 @@ Phaser.Renderer.Canvas = function (game)
9092
9193 this . blendModes = [ so , 'lighter' , so , so , so , so , so , so , so , so , so , so , so , so , so , so , so ] ;
9294
95+ this . currentAlpha = 1 ;
9396 this . currentBlendMode = 0 ;
9497 this . currentScaleMode = 0 ;
9598
@@ -183,21 +186,27 @@ Phaser.Renderer.Canvas.prototype = {
183186 */
184187 render : function ( stage )
185188 {
186- // this first setTransform, alpha, etc could all be set direct
187- // from the Stage values - as they're the basis really
188-
189189 this . context . setTransform ( 1 , 0 , 0 , 1 , 0 , 0 ) ;
190- this . context . globalAlpha = 1 ;
191- this . context . globalCompositeOperation = 'source-over' ;
190+
191+ // If the alpha or blend mode didn't change since the last render, then don't set them again
192+ // (saves 2 canvas ops)
193+
194+ if ( this . currentAlpha !== 1 )
195+ {
196+ this . context . globalAlpha = 1 ;
197+ }
198+
199+ if ( this . currentBlendMode !== 0 )
200+ {
201+ this . context . globalCompositeOperation = 'source-over' ;
202+ }
192203
193204 this . currentBlendMode = 0 ;
194205 this . currentScaleMode = 0 ;
206+ this . currentAlpha = 1 ;
195207
196208 // Add Pre-render hook
197209
198- // this.renderSession.shakeX = this.game.camera._shake.x;
199- // this.renderSession.shakeY = this.game.camera._shake.y;
200-
201210 // Is this needed any longer?
202211 /*
203212 if (navigator.isCocoonJS && this.view.screencanvas)
@@ -209,15 +218,7 @@ Phaser.Renderer.Canvas.prototype = {
209218
210219 if ( this . clearBeforeRender )
211220 {
212- if ( this . transparent )
213- {
214- this . context . clearRect ( 0 , 0 , this . width , this . height ) ;
215- }
216- else if ( stage . _bgColor )
217- {
218- this . context . fillStyle = stage . _bgColor . rgba ;
219- this . context . fillRect ( 0 , 0 , this . width , this . height ) ;
220- }
221+ this . context . clearRect ( 0 , 0 , this . width , this . height ) ;
221222 }
222223
223224 stage . render ( this , stage ) ;
0 commit comments