Skip to content

Commit b3486ad

Browse files
committed
Added getPixel method to the Texture Manager.
1 parent 2405160 commit b3486ad

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'bed52b20-68b5-11e7-9844-9578aae7c468'
2+
build: '7951fe00-6a1a-11e7-b2f7-691420b8f38d'
33
};
44
module.exports = CHECKSUM;

v3/src/textures/TextureManager.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
var CanvasPool = require('../dom/CanvasPool');
33
var Class = require('../utils/Class');
4+
var Color = require('../graphics/color/Color');
45
var GenerateTexture = require('../create/GenerateTexture');
56
var GetValue = require('../utils/object/GetValue');
67
var 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

Comments
 (0)