mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 21:53:59 +00:00
Limit textures probed by TextureManager.getPixel
and getPixelAlpha
.
This commit is contained in:
parent
3c7bee4e08
commit
0a2bede95e
2 changed files with 19 additions and 2 deletions
|
@ -14,6 +14,7 @@
|
|||
# Bug Fixes
|
||||
|
||||
* Fix `LightPipeline` failing to render the same normal map twice in a row in a single batch, by removing `setTexture2D`. Fix #6708 (thanks @sroboubi)
|
||||
* Log a warning instead of throwing an exception when calling `TextureManager.getPixel()` or `getPixelAlpha()` on textures that cannot be drawn to a canvas for sampling. Fix #6761 (thanks @yaustar)
|
||||
|
||||
## Examples, Documentation, Beta Testing and TypeScript
|
||||
|
||||
|
|
|
@ -1415,6 +1415,14 @@ var TextureManager = new Class({
|
|||
|
||||
if (textureFrame)
|
||||
{
|
||||
var source = textureFrame.source;
|
||||
var image = source.image;
|
||||
if (!(source.isCanvas || source.isVideo || image instanceof HTMLImageElement))
|
||||
{
|
||||
console.warn('TextureManager.getPixelAlpha: The texture source must be Image, Canvas, or Video');
|
||||
return null;
|
||||
}
|
||||
|
||||
// Adjust for trim (if not trimmed x and y are just zero)
|
||||
x -= textureFrame.x;
|
||||
y -= textureFrame.y;
|
||||
|
@ -1429,7 +1437,7 @@ var TextureManager = new Class({
|
|||
var ctx = this._tempContext;
|
||||
|
||||
ctx.clearRect(0, 0, 1, 1);
|
||||
ctx.drawImage(textureFrame.source.image, x, y, 1, 1, 0, 0, 1, 1);
|
||||
ctx.drawImage(image, x, y, 1, 1, 0, 0, 1, 1);
|
||||
|
||||
var rgb = ctx.getImageData(0, 0, 1, 1);
|
||||
|
||||
|
@ -1461,6 +1469,14 @@ var TextureManager = new Class({
|
|||
|
||||
if (textureFrame)
|
||||
{
|
||||
var source = textureFrame.source;
|
||||
var image = source.image;
|
||||
if (!(source.isCanvas || source.isVideo || image instanceof HTMLImageElement))
|
||||
{
|
||||
console.warn('TextureManager.getPixelAlpha: The texture source must be Image, Canvas, or Video');
|
||||
return null;
|
||||
}
|
||||
|
||||
// Adjust for trim (if not trimmed x and y are just zero)
|
||||
x -= textureFrame.x;
|
||||
y -= textureFrame.y;
|
||||
|
@ -1475,7 +1491,7 @@ var TextureManager = new Class({
|
|||
var ctx = this._tempContext;
|
||||
|
||||
ctx.clearRect(0, 0, 1, 1);
|
||||
ctx.drawImage(textureFrame.source.image, x, y, 1, 1, 0, 0, 1, 1);
|
||||
ctx.drawImage(image, x, y, 1, 1, 0, 0, 1, 1);
|
||||
|
||||
var rgb = ctx.getImageData(0, 0, 1, 1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue