如何跟踪旋转MovieClip上的点?

发布于 2025-01-05 18:17:54 字数 287 浏览 1 评论 0原文

我有一个 MovieClip,它代表我游戏中的一个角色。我想“创造子弹”从我的角色枪尖射出。问题是,当我的角色转身时,该点也会围绕 MovieClips 枢轴旋转。

是否有可能轻松地跟踪这一点,以便我可以在同一位置动态创建新对象。

我尝试在我的角色小时候添加一个新的MC,初始位置在枪尖。在某些系统中,子对象“跟随”其父母,但在这里似乎不起作用。

是否有任何其他“本地”方法可以做到这一点,或者我只需要相对于角色MovieClips原点的点的极坐标表示,并将MC旋转添加到theta,以便我可以计算X和Y 坐标?

I have a MovieClip, that is representing a character in my game. Id like to "create bullets" shooting out from the tip of my characters gun. Problem is that when my character turns around, also the point rotates around the MovieClips pivot.

Is it possible to anyhow easily track this point, so that I could dynamically create new objects at the same location.

I tried to add a new MC as a child to my character, with the initial position at the guntip. In some systems child-objects "follow" their parents around, but it didnt seem to work here.

Is there any other "native" way of doing this, or do I just have to have a Polar-coordinates representation of the point relative to character-MovieClips origin, and add the MC rotation to theta, so that I can calculate the X and Y coordinates?

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

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

发布评论

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

评论(2

情丝乱 2025-01-12 18:17:54

尝试 localToGlobal()< /a> 和 globalToLocal() 方法将坐标从角色动画剪辑转换到其父级。

Try localToGlobal() and globalToLocal() methods to transform coordinates from your character movieclip to its parent.

醉态萌生 2025-01-12 18:17:54

用枪设置影片剪辑(我假设它位于手臂的末端?),以便枪尖直接穿过枢轴点。

然后向发射子弹的方法传递三个参数:枪MC的x和y位置,以及它的当前角度。

子弹初始位置的代码可能如下所示:

public function CreateBullet(x,y:Number, degree:Number)
{
    // set start position
    this.x = x + ARMLENGTH*Math.cos((degree/180)*Math.PI);
    this.y = y + ARMLENGTH*Math.sin((degree/180)*Math.PI);
}

其中 ARMLENGTH 是从枢轴点到枪末端的距离。

两个警告,Flash 可以用角度做一些奇怪的事情,所以如果玩家面向后,您可能必须在 CreateBullet() 中使用倒置的度数进行 if 语句。另外,如果您将枪 MC 作为角色的子级,您可能必须在枢轴点所在的位置创建一个 Point,然后对其执行 localToGlobal。 此处有一个很好的参考。

Set up the movie clip with the gun (I'm assuming it's at the end of an arm?) so that the gun tip is straight across from the pivot point.

Then pass the method that fires the bullet three parameters: the x and y position of the gun MC, and its current angle.

The code for your bullets initial position might look something like this:

public function CreateBullet(x,y:Number, degree:Number)
{
    // set start position
    this.x = x + ARMLENGTH*Math.cos((degree/180)*Math.PI);
    this.y = y + ARMLENGTH*Math.sin((degree/180)*Math.PI);
}

Where ARMLENGTH is the distance from the pivot point to the end of the gun.

Two caveats, Flash can do weird things with angles, so you might have to make an if statement in CreateBullet() with inverted degrees if the player if facing backwards. Also, if you have the gun MC as a child of your character, you might have to make a Point where the pivot point is then do a localToGlobal on it. There's a good reference for that here.

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