55*/
66
77var CONST = require ( '../const' ) ;
8+ var Smoothing = require ( './Smoothing' ) ;
89
910/**
1011 * The pool into which the canvas elements are placed.
@@ -14,6 +15,9 @@ var CONST = require('../const');
1415 */
1516var pool = [ ] ;
1617
18+ // Automatically apply smoothing(false) to created Canvas elements
19+ var _disableContextSmoothing = false ;
20+
1721// This singleton is instantiated as soon as Phaser loads,
1822// before a Phaser.Game instance has even been created.
1923// Which means all instances of Phaser Games on the same page
@@ -39,6 +43,8 @@ var CanvasPool = function ()
3943 */
4044 var create = function ( parent , width , height , type )
4145 {
46+ // console.log('CanvasPool.create', parent);
47+
4248 if ( width === undefined ) { width = 1 ; }
4349 if ( height === undefined ) { height = 1 ; }
4450 if ( type === undefined ) { type = CONST . CANVAS ; }
@@ -71,6 +77,11 @@ var CanvasPool = function ()
7177
7278 canvas . width = width ;
7379 canvas . height = height ;
80+
81+ if ( _disableContextSmoothing && type === CONST . CANVAS )
82+ {
83+ Smoothing . disable ( canvas . getContext ( '2d' ) ) ;
84+ }
7485
7586 return canvas ;
7687 } ;
@@ -110,7 +121,7 @@ var CanvasPool = function ()
110121 /**
111122 * Looks up a canvas based on its parent, and if found puts it back in the pool, freeing it up for re-use.
112123 * The canvas has its width and height set to 1, and its parent attribute nulled.
113- *
124+ *
114125 * @static
115126 * @method Phaser.CanvasPool.remove
116127 * @param {any|HTMLCanvasElement } parent - The parent of the canvas element.
@@ -134,7 +145,7 @@ var CanvasPool = function ()
134145
135146 /**
136147 * Gets the total number of used canvas elements in the pool.
137- *
148+ *
138149 * @static
139150 * @method Phaser.CanvasPool.getTotal
140151 * @return {number } The number of in-use (parented) canvas elements in the pool.
@@ -156,7 +167,7 @@ var CanvasPool = function ()
156167
157168 /**
158169 * Gets the total number of free canvas elements in the pool.
159- *
170+ *
160171 * @static
161172 * @method Phaser.CanvasPool.getFree
162173 * @return {number } The number of free (un-parented) canvas elements in the pool.
@@ -166,15 +177,29 @@ var CanvasPool = function ()
166177 return pool . length - total ( ) ;
167178 } ;
168179
180+ // Disable context smoothing on any new Canvas element created
181+ var disableSmoothing = function ( )
182+ {
183+ _disableContextSmoothing = true ;
184+ } ;
185+
186+ // Enable context smoothing on any new Canvas element created
187+ var enableSmoothing = function ( )
188+ {
189+ _disableContextSmoothing = false ;
190+ } ;
191+
169192 return {
170- create : create ,
171193 create2D : create2D ,
194+ create : create ,
172195 createWebGL : createWebGL ,
196+ disableSmoothing : disableSmoothing ,
197+ enableSmoothing : enableSmoothing ,
173198 first : first ,
174- remove : remove ,
175- total : total ,
176199 free : free ,
177- pool : pool
200+ pool : pool ,
201+ remove : remove ,
202+ total : total
178203 } ;
179204} ;
180205
0 commit comments