AS3中bitmapData的放置坐标

发布于 2024-08-27 16:46:11 字数 656 浏览 3 评论 0原文

我以编程方式创建了一个矢量图形(矩形),重新定位了该图形,并设置了 MOUSE_MOVE 事件监听器以使用 getPixel() 跟踪图形的颜色信息。但是,位图数据放置在舞台的 0,0 处,我不知道如何移动它以使其与图形的位置匹配。

var coloredSquare:Sprite = new GradientRect(200, 200, 0xFFFFFF, 0x000000, 0xFF0000, 0xFFFF00);
coloredSquare.x = 100;

addChild(coloredSquare);

var coloredSquareBitmap:BitmapData = new BitmapData(coloredSquare.width, coloredSquare.height, true, 0);
coloredSquareBitmap.draw(coloredSquare);

coloredSquare.addEventListener(MouseEvent.MOUSE_MOVE, readColor);
function readColor(evt:Event):void
    {
    var pixelValue:uint = coloredSquare.getPixel(mouseX, mouseY);
    trace(pixelValue.toString(16));
    }

i've programatically created a vector graphic (rect), repositioned the graphic, and set up an MOUSE_MOVE eventListener to trace color information of the graphic using getPixel(). however, the bitmapData is placed at 0,0 of the stage and i don't know how to move it so that it matches the graphic's location.

var coloredSquare:Sprite = new GradientRect(200, 200, 0xFFFFFF, 0x000000, 0xFF0000, 0xFFFF00);
coloredSquare.x = 100;

addChild(coloredSquare);

var coloredSquareBitmap:BitmapData = new BitmapData(coloredSquare.width, coloredSquare.height, true, 0);
coloredSquareBitmap.draw(coloredSquare);

coloredSquare.addEventListener(MouseEvent.MOUSE_MOVE, readColor);
function readColor(evt:Event):void
    {
    var pixelValue:uint = coloredSquare.getPixel(mouseX, mouseY);
    trace(pixelValue.toString(16));
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七颜 2024-09-03 16:46:11

使用正方形的变换矩阵(也包含平移)作为 draw() 方法

,例如

coloredSquareBitmap.draw(coloredSquare,coloredSquare.transform.matrix);

Use the square's transformation matrix (which contains the translation as well) as the second parameter of the draw() method

e.g.

coloredSquareBitmap.draw(coloredSquare,coloredSquare.transform.matrix);
ゞ记忆︶ㄣ 2024-09-03 16:46:11

我不完全理解问题或代码。也许这有帮助:

coloredSquareBitmap.draw(coloredSquare, coloredSquare.transform.concatenatedMatrix);

I do not fully understand the problem or the code. Maybe this helps:

coloredSquareBitmap.draw(coloredSquare, coloredSquare.transform.concatenatedMatrix);
情深已缘浅 2024-09-03 16:46:11

使用

var pixelValue:uint = coloredSquare.getPixel(coloredSquare.mouseX, coloredSquare.mouseY);

这种方式,mouseX / mouseY 将位于彩色方块的本地,因此位图会重复。

Use

var pixelValue:uint = coloredSquare.getPixel(coloredSquare.mouseX, coloredSquare.mouseY);

That way the mouseX / mouseY will be local to the coloured square and thus the bitmap duplicate .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文