Flash CS4 AS3 水平影片剪辑随鼠标移动滚动
我是 AS3 的新手,一直致力于用 AS3 编写的 XML 驱动的导航系统。
目前,我已导入 XML 文件的内容,并将其绘制在舞台上动态创建的根级别包含的 MovieClip 中。 这个MovieClip被称为“容器”。
我想要实现的是平滑的加速/减速效果,根据鼠标光标相对于舞台中间的位置,沿 X 轴对容器影片剪辑进行动画处理。
我的代码可以在这里找到:http://pastie.org/521432
行87 以后是我现在使用的代码,用于使影片剪辑向左滚动和向右滚动。 正确的。
我所拥有的确实有效,但很笨重,但确实有效——我只是希望它更加精致一点,并且在谷歌上留下了空白。 因为我希望即使鼠标停止移动,MovieClip 也能继续以当前相对速度滚动,所以我使用了 Timer 类的实例。
有人可以提出改进建议吗? 提前致谢。
I'm new to AS3 and have been working on an XML driven navigation system written in AS3.
At present, I've imported the contents of an XML file and plotted it inside a containing MovieClip created at root level dynamically on the stage. This MovieClip is called 'container'.
What I want to accomplish is a smooth, accelerating / decelerating effect which animates the container movieclip along the X axis depending on where the mouse cursor is in relation to the middle of the stage.
My code can be found here: http://pastie.org/521432
Line 87 onwards is the code I'm using right now to make the movieclip scroll left & right.
What I have does work but is clunky but does work - I just want it to be a little more polished and have drawn a blank with Google. Because I want the MovieClip to continue to scroll at the current relative speed even when the mouse stops moving, I used an instance of the Timer class.
Can anyone suggest improvements? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将计算和绘图方法分开。 因此,让它在 onMouseMove 处理程序中执行所有计算,但实际上在 onEnterFrame 处理程序中绘制更改。
另外我认为你的算法可以更简单,没有人会注意到。 我举了一个简单的例子来说明你可以如何做到这一点。 将此代码粘贴到名为 Main.as 的 AS3 文件中,并使其成为新 FLA 的文档类。
You should separate out you calculations and your drawing methods. So have it do all the calculations in an onMouseMove handler, but actually draw the changes in an onEnterFrame handler.
Also I think your algorithm could be much simpler and nobody would notice. I made a quick example of how you might do it. paste this code into an AS3 file called Main.as and make it the document class of a new FLA.