creator 2.4.8中获取像素信息

有大佬知道,creator2.4.8中通过RenderTexture获取像素信息来控制点击透明穿透,但作用节点scale缩放后,像素信息就对不上了,控制相机拍摄尺寸也对不上
image

1赞

请问你是在读取像素之前就对目标节点 scale 么?

var PixelHitTest = (function () {
function PixelHitTest(data, offsetX, offsetY) {
this._data = data;
this.offsetX = offsetX == undefined ? 0 : offsetX;
this.offsetY = offsetY == undefined ? 0 : offsetY;
this.scaleX = 1;
this.scaleY = 1;
}
PixelHitTest.prototype.hitTest = function (pt) {
var x = Math.floor((pt.x / this.scaleX - this.offsetX) * this._data.scale);
var y = Math.floor((pt.y / this.scaleY - this.offsetY) * this._data.scale);
if (x < 0 || y < 0 || x >= this._data.pixelWidth)
return false;
var pos = y * this._data.pixelWidth + x;
var pos2 = Math.floor(pos / 8);
var pos3 = pos % 8;
if (pos2 >= 0 && pos2 < this._data.pixels.length)
return ((this._data.pixels[pos2] >> pos3) & 0x1) == 1;
else
return false;
};
return PixelHitTest;
}());

所以你知道这个问题中,他是先 scale 再读取像素的还是先读取像素再 scale 的?你的代码我看不懂,和上面的代码没有连贯性。