[]画了一个封闭的曲线,获取鼠标点击处的像素,为何坐标对不上导致拿不到正确位置的Texture?

package
{
import laya.display.Sprite;
import laya.display.Stage;
import laya.events.Event;
import laya.resource.HTMLCanvas;
import laya.resource.Texture;

import rain.core.StageReferance;

public class Main
{

private var _view:Sprite;

public function Main()
{
Config.isAntialias = true;//抗锯齿
//初始化引擎
Laya.init(1024, 768);
//Stat.show();
Laya.stage.bgColor = "#ccc";
Laya.stage.scaleMode = Stage.SCALE_SHOWALL;
Laya.stage.alignH = Stage.ALIGN_CENTER;
Laya.stage.alignV = Stage.ALIGN_MIDDLE;
StageReferance.setup(Laya.stage);

init();
}

private function init():void
{
_view = new Sprite();
var points:Array = [12,41, 0,72, 36,74, 76,72, 60,41, 36,-26, 12,41];
// 从0,0点开始画一个封闭的曲线
_view.graphics.drawCurves(0,0, points, "#ff0000", 15);
Laya.stage.addChild(_view);
_view.size(80, 100);
_view.on(Event.CLICK, this, __clickHandler);
}

private function __clickHandler():void
{
trace(_view.stage.mouseX + "---" + _view.stage.mouseY);
/*获取所画曲线鼠标点击处的像素,为何坐标对不上?导致无法拿到正确位置的Texture*/
var hc:HTMLCanvas = _view.drawToCanvas(1, 1, _view.stage.mouseX, _view.stage.mouseY);
var tex:Texture = new Texture(hc);
trace(tex.width + "---" + tex.height + "---" + getPixel(tex));
/*获取所画曲线鼠标点击处的像素,为何坐标对不上?
导致无法拿到正确位置的Texture*/

/*var spr:Sprite = new Sprite();
spr.graphics.drawTexture(tex);
this.addChild(spr);
spr.pos(90, 0);*/
}

private function getPixel(tex:Texture):int
{
var pixelCount:int = 0;
var arr:Array = tex.getPixels(0, 0, tex.width, tex.height);
for(var i:int = 0; i < arr.length; i++)
{
if(arr[i] > 0)
{
pixelCount++;
}
}
return pixelCount;
}
}
}[/i]
已邀请:

Charles

赞同来自:

明明mouseX和mouseY的坐标就是所点击处的位置啊,为何drawToCanvas却不是绘制该坐标处的部分呢?
这都是同一个对象内,也并不需要坐标转换啊?

要回复问题请先

商务合作
商务合作