Actionscript 3 Actionscript 3 bitmapdata.draw使用矩阵画笔
我正在写一个画图程序,它使用形状笔刷,通过使用矩阵函数来画图。 除了一点都不顺利之外,一切都很顺利。如果鼠标高速移动,绘画中会有间隙 我到处找了,但没找到任何解决办法 代码基本上如下所示:Actionscript 3 Actionscript 3 bitmapdata.draw使用矩阵画笔,actionscript-3,actionscript,matrix,draw,bitmapdata,Actionscript 3,Actionscript,Matrix,Draw,Bitmapdata,我正在写一个画图程序,它使用形状笔刷,通过使用矩阵函数来画图。 除了一点都不顺利之外,一切都很顺利。如果鼠标高速移动,绘画中会有间隙 我到处找了,但没找到任何解决办法 代码基本上如下所示: //Press mouse within container. Uses Matrix to draw instances of the brush. private function handleMouseDown_drawContainer(e:MouseEvent):void {
//Press mouse within container. Uses Matrix to draw instances of the brush.
private function handleMouseDown_drawContainer(e:MouseEvent):void
{
_matrix.identity();
_matrix.translate(mouseX - 10, mouseY - 30);
_layout.bitmapData.draw(_layout.brush, _matrix);
_layout.drawContainer.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove_drawContainer);
_layout.drawContainer.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp_drawContainer)
}
//Move mouse within container. Uses Matrix to draw instances of the brush.
private function handleMouseMove_drawContainer(e:MouseEvent):void
{
_matrix.identity();
_matrix.translate(mouseX - 10, mouseY - 30);
_layout.bitmapData.draw(_layout.brush, _matrix);
}
如果有人能帮我弄清楚如何画得流畅,我将永远感激=p
提前感谢。您可能需要在鼠标位置之间进行某种插值。。。当然有很多方法,我将描述一种非常容易实现但有点难以微调的方法。基本上,你不用在每个鼠标位置上画图,而是使用一个跟随鼠标的缓和方程,并有一些延迟。。。这样,所描述的线条将更加平滑,并在每个鼠标位置之间绘制几次。
因此,不要执行(伪代码): 你可以这样做:
x = 0;
y = 0;
onEnterFrame {
x += (mouseX - x) * 0.2;
y += (mouseY - y) * 0.2;
draw(x, y);
}
虽然您真正需要的可能是限制点之间最大距离的方法,因此如果鼠标在一帧中移动更多,您可以在两个位置之间插入点,并根据需要多次绘制。或者,如果您正在寻找更平滑的线条(避免尖角),可能还需要使用Bezier来控制生成的线条。
无论如何,这都取决于你要找的画的类型
x = 0;
y = 0;
onEnterFrame {
x += (mouseX - x) * 0.2;
y += (mouseY - y) * 0.2;
draw(x, y);
}