AS3 ActionScript绘制大纲

发布于 2025-02-13 12:34:55 字数 314 浏览 0 评论 0原文

我正在使用Adobe Air和AS3开发着着色游戏。我有一个带有黑色轮廓的图像,用户可以使用笔工具绘制图像。我需要帮助才能弄清楚如何限制用户仅在大纲中绘制。我已经尝试过用线条图形掩盖图像,但它悬挂了应用程序。对解决方案的任何提示 /建议都得到赞赏。

以下是Mouse_down事件上的代码

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

I am developing a coloring game using adobe air and as3. I have an image with black outline and the user can draw / color the image using a pen tool. I need help to figure out how can I restrict the user to draw within the outlines only. Masking the image with the line-graphics is something I have tried but it hangs the application. Any hint / suggestion towards the solution is appreciated.

following is the code on mouse_down event

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

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

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

发布评论

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

评论(1

梦初启 2025-02-20 12:34:56

假设您要绘制的区域是 displayObject ,其实例名称为 canvas 。您需要检查鼠标是否在画布上

为此,您要使用 displayObject.hittestpoint(...) shapeflag 设置为 true (如果它是 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.
}

Let's say, the area you are drawing on is a DisplayObject with an instance name of Canvas. What you need is to check if the mouse is on Canvas or not.

In order to do so, you want to use the DisplayObject.hitTestPoint(...) method with the shapeFlag set to true (if it is false, it tests the point against the object's rectangle bounding box, which would produce the wrong results for any non-rectangular or rotated shapes).

So, you do as following:

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