But there is not possible to get color of individual pixels. Its always return zero.
I tried to saveTexture with some key, extract it and then get color - but result is the same.
What I am doing wrong ?
It works only for game type = Phaser.CANVAS.
if I set type = Phaser.AUTO then it using webgl rendering and returns always zero.
How to get pixel in this case?
There is another method to get area, but it also returns data inside callback.
this.game.renderer.snapshotArea(pointer.x, pointer.y, 128, 128, function (image) {
document.body.appendChild(image);
if (textureManager.exists('area'))
{
textureManager.remove('area');
}
textureManager.addImage('area', image);
particles.setTexture('area');
});
And again, my goal is way to detect scratched area of existing renderTexture object. Idea was to get all pixels and check color. I don’t understand how to do that with folowing methods.
Strange. I tested on the OP’s CodePen. The global method works, the RenderTexture one doesn’t.
If I look at the Phaser code, it shouldn’t make any difference? It just passes through, based on Canvas or WebGL…
In that pen, userCanvas.snapshotArea(…) does snapshot correctly, but I think userCanvas.context.getImageData(…) will always get a blank pixel in WEBGL mode.
Did anybody manage to get the pixel data of RenderTexture with snapshotPixel method correctly?
Other thing is, that although the game.renderer.snapshotPixel method correctly returns the color value of the pixel rom the game canvas image, the alpha value is max 1 for non-transparent pixel (should be 255), and alphaGL is max 0.00392156862745098 (should be 1).