As3 Actionscript在轮廓内绘制



我正在使用adobe air和as3开发一个着色游戏。我有一个黑色轮廓的图像,用户可以使用钢笔工具绘制/上色图像。我需要帮助弄清楚如何才能限制用户只在轮廓内绘制。用线条图形遮罩图像是我尝试过的,但它会挂起应用程序。对于解决方案的任何提示/建议,我们都很感激。

下面是mouse_down事件

的代码
_dot = new MovieClip();
_dot.graphics.lineStyle(lineSize, color);
_dot.graphics.moveTo(img.mouseX,img.mouseY);
img.addChild(_dot);

比如说,你要绘制的区域是一个DisplayObject实例名为Canvas. 你需要做的是检查鼠标是否在Canvas上。

为了做到这一点,你需要使用DisplayObject.hitTestPoint(…)方法和shapeFlag(如果false),它根据对象的矩形边界框测试该点,对于任何非矩形或旋转的形状,这将产生错误的结果)。

,你做如下:

var P:Point = new Point;
// First, convert coordinates to Stage coordinates,
// because the method requires so.
P.x = Canvas.mouseX;
P.y = Canvas.mouseY;
P = Canvas.localToGlobal(P);
// Now, test if the mouse is within the given canvas.
if (Canvas.hitTestPoint(P.x, P.y, true))
{
// The drawing should happen here.
}

最新更新