如何跟踪旋转MovieClip上的点?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 localToGlobal()< /a> 和 globalToLocal() 方法将坐标从角色动画剪辑转换到其父级。
Try localToGlobal() and globalToLocal() methods to transform coordinates from your character movieclip to its parent.
用枪设置影片剪辑(我假设它位于手臂的末端?),以便枪尖直接穿过枢轴点。
然后向发射子弹的方法传递三个参数:枪MC的x和y位置,以及它的当前角度。
子弹初始位置的代码可能如下所示:
其中 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:
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.