动作脚本可移动点和线

发布于 2024-12-12 05:22:24 字数 255 浏览 0 评论 0原文

我对动作脚本还很陌生,我对正在制作的游戏有几个问题:

  1. 如何使 MovieClip 对象可以通过鼠标拖动?
  2. 如果我有两个 MovieClip 实例,是否可以创建一个看起来像一条线的新形状/MovieClip 对象,然后将其连接起来?
  3. 我有函数检查“节点”影片剪辑实例是否与“线”影片剪辑实例碰撞,现在这些都是不同的函数和条件,但是是否可以检查它们是否全部为真?

感谢您的任何帮助。说真的,任何帮助都很棒。

I'm pretty new to Action Script and I have a couple of questions of a game i am making:

  1. How can i make a MovieClip object drag able by the mouse?
  2. If i have two MovieClip instances, is it possible to make a new shape/MovieClip objects in that looks like a line and which will connect then?
  3. I have functions checking if the 'nodes' movie clip instances collide with the 'line' movie clip instances, now these all are different functions and conditional, but is it possible to check if ALL of them are true?

Thanks for ANY help. Seriously, ANY help is great.

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

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

发布评论

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

评论(2

倾城月光淡如水﹏ 2024-12-19 05:22:24

首先制作一个可拖动的 MovieClip 非常简单,您只需要执行 mc.startDrag();和 mc.stopDrag();停止移动...

通常这是与 MOUSE_DOWN 和 MOUSE_UP 事件一起完成的示例:

mc.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent):void
{
    e.currentTarget.startDrag();
});

mc.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void
{
    e.currentTarget.stopDrag();
});

您还可以定义锁定中心或限制 startDrag 方法上的拖动的矩形,基本上如果锁定中心为真,则鼠标将粘在拖动时影片剪辑的中心,矩形将限制拖动区域,例如画布。

第二个问题,

您可以在 AS3 中创建一个新的 MC,如下所示 var mc:MovieClip = new MovieClip();
然后用图形在 MC 中画线...

更详细的示例:

var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0x000000);
mc.graphics.lineStyle(2,0x000000);

//start drawing the line
mc.graphics.moveTo(10,10);
mc.graphics.lineTo(10,100);
mc.graphics.endFill();

//Position your new movie clip
mc.x = 80;
mc.y = 60;
addChild(mc);

最后我不确定您如何实现碰撞检测,但您也许可以为每个项目拥有一个状态数组,并在发生碰撞时更改它们你可以循环进入数组来检查它们是否全部为真......

Well first making a MovieClip draggable is pretty simple, you just need to do mc.startDrag(); and mc.stopDrag(); to stop the movment...

Usually this is done along with the MOUSE_DOWN and MOUSE_UP events example:

mc.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent):void
{
    e.currentTarget.startDrag();
});

mc.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void
{
    e.currentTarget.stopDrag();
});

You can also define to lock center or a rect which limits the drag on the startDrag method, basically if lock center is true the mouse will stick to the center of the MovieClip while dragging and the rectangle will limit the drag area for example a canvas.

Second question,

You can create a new MC in AS3 like this var mc:MovieClip = new MovieClip();
then draw the line in the MC with the graphics...

A more detailed example:

var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0x000000);
mc.graphics.lineStyle(2,0x000000);

//start drawing the line
mc.graphics.moveTo(10,10);
mc.graphics.lineTo(10,100);
mc.graphics.endFill();

//Position your new movie clip
mc.x = 80;
mc.y = 60;
addChild(mc);

Finally im not sure how you implemented the collision detection but you may be able to have an array of states for each item and change them when something has collided then you can loop into the array to check for all of them to be true...

幽蝶幻影 2024-12-19 05:22:24

1)查看 startDrag/stopDrag 方法。然后可以在 Sprite 或其任何子类上调用

2) 是的,您可以使用 graphics 任何 Sprite 的对象来绘制任意线条/形状

3) 为了检测多个对象的碰撞,您必须逐步遍历每个对象。尝试使用 for 循环

1) look at the startDrag/stopDrag methods. Then can be called on Sprite or any of its subclass

2) yes, you can use the graphics object of any Sprite to draw arbitrary lines/shapes

3) for collision detecting multiple objects, you'll have to step through each object. try using a for loop

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