AS3中bitmapData的放置坐标
我以编程方式创建了一个矢量图形(矩形),重新定位了该图形,并设置了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用正方形的变换矩阵(也包含平移)作为
draw()
方法,例如
Use the square's transformation matrix (which contains the translation as well) as the second parameter of the
draw()
methode.g.
我不完全理解问题或代码。也许这有帮助:
I do not fully understand the problem or the code. Maybe this helps:
使用
这种方式,mouseX / mouseY 将位于彩色方块的本地,因此位图会重复。
Use
That way the mouseX / mouseY will be local to the coloured square and thus the bitmap duplicate .