11
22var CanvasPool = require ( '../dom/CanvasPool' ) ;
33var Class = require ( '../utils/Class' ) ;
4+ var Color = require ( '../graphics/color/Color' ) ;
45var GenerateTexture = require ( '../create/GenerateTexture' ) ;
56var GetValue = require ( '../utils/object/GetValue' ) ;
67var Parser = require ( './parsers' ) ;
@@ -27,6 +28,9 @@ var TextureManager = new Class({
2728
2829 this . list = { } ;
2930
31+ this . _tempCanvas = CanvasPool . create2D ( this , 1 , 1 ) ;
32+ this . _tempContext = this . _tempCanvas . getContext ( '2d' ) ;
33+
3034 this . addBase64 ( '__DEFAULT' , game . config . defaultImage ) ;
3135 this . addBase64 ( '__MISSING' , game . config . missingImage ) ;
3236 } ,
@@ -287,6 +291,39 @@ var TextureManager = new Class({
287291 }
288292 } ,
289293
294+ getPixel : function ( x , y , key , frame )
295+ {
296+ var textureFrame = this . getFrame ( key , frame ) ;
297+
298+ if ( textureFrame )
299+ {
300+ var source = textureFrame . source . image ;
301+
302+ if ( x >= 0 && x <= source . width && y >= 0 && y <= source . height )
303+ {
304+ x += textureFrame . cutX ;
305+ y += textureFrame . cutY ;
306+
307+ // if (textureFrame.trimmed)
308+ // {
309+ // x -= this.sprite.texture.trim.x;
310+ // y -= this.sprite.texture.trim.y;
311+ // }
312+
313+ var context = this . _tempContext ;
314+
315+ context . clearRect ( 0 , 0 , 1 , 1 ) ;
316+ context . drawImage ( source , x , y , 1 , 1 , 0 , 0 , 1 , 1 ) ;
317+
318+ var rgb = context . getImageData ( 0 , 0 , 1 , 1 ) ;
319+
320+ return new Color ( rgb . data [ 0 ] , rgb . data [ 1 ] , rgb . data [ 2 ] , rgb . data [ 3 ] ) ;
321+ }
322+ }
323+
324+ return null ;
325+ } ,
326+
290327 setTexture : function ( gameObject , key , frame )
291328 {
292329 if ( this . list [ key ] )
0 commit comments