如何设置MovieClip位置而不弄乱补间?
我正在开发带有移动平台的 AS3 和 Box2D 游戏。这些平台在 Flash 中进行动画处理,在 ActionScript 中我可以读取其当前位置并调整物理体以进行匹配。
然而,总是存在延迟,即动画比物理提前一帧。我想通过读取剪辑的当前位置,将其存储以供以后使用,然后将剪辑放回到最后一帧的位置来解决此问题。
但当我这样做时,它系统地拒绝让步。
我用一个移动框编写了一个简单的测试来测试这个想法,我遇到了同样的问题(“movingBox”是一个符号,它为其中的单个“框”符号设置动画):
package
{
import flash.display.*;
import flash.events.*;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
m_movingBox = new MovingBoxClass();
addChild(m_movingBox);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(i_event:Event) : void
{
const box : Sprite = m_movingBox.getChildAt(0) as Sprite;
trace("frame:", m_movingBox.currentFrame, ", x:", box.x);
box.x = 0;
}
[Embed(source="../lib.swf", symbol="movingBox")]
private var MovingBoxClass:Class;
private var m_movingBox : MovieClip;
}
}
而不是打印出移动的位置盒子,盒子保持静止,跟踪调用输出:
frame: 1 , x: 0
frame: 2 , x: 0
frame: 3 , x: 0
frame: 4 , x: 0
frame: 5 , x: 0
...
有什么想法吗?谢谢
更新: 需要明确的是,如果我删除 box.x = 0;
行,则框会正确移动,并且跟踪调用会输出 x 的递增值。
更新:我举了一些例子:
I'm working on a AS3 and Box2D game with moving platforms. The platforms are animated in Flash, and in actionscript I can read in their current position and adjust the physics bodies to match.
However, there's always a delay, where the animation is one frame ahead of the physics. I wanted to fix this by reading in the clip's current position, storing it for later, and then putting the clip back to its position at the last frame.
But when I do this, it systematically refuses to budge.
I coded up a simple test with a single moving box to test the idea, and I get the same problem ("movingBox" is a symbol that animates a single "box" symbol within it):
package
{
import flash.display.*;
import flash.events.*;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
m_movingBox = new MovingBoxClass();
addChild(m_movingBox);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(i_event:Event) : void
{
const box : Sprite = m_movingBox.getChildAt(0) as Sprite;
trace("frame:", m_movingBox.currentFrame, ", x:", box.x);
box.x = 0;
}
[Embed(source="../lib.swf", symbol="movingBox")]
private var MovingBoxClass:Class;
private var m_movingBox : MovieClip;
}
}
Instead of printing out the positions of the moving box, the box just stays still, and the trace call outputs:
frame: 1 , x: 0
frame: 2 , x: 0
frame: 3 , x: 0
frame: 4 , x: 0
frame: 5 , x: 0
...
Any ideas? Thanks
UPDATE: Just to be clear, if i remove the box.x = 0;
line, the box moves correctly and the trace call spits out increasing values for x.
UPDATE: I put up the examples:
The lib, with "movingBox" on the stage
Zip file containing the Flash Develop project and all the rest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:
现在您可以管理此动画并调整每帧的其他坐标
upd:
now you can manage this animation and adjust other coords every frame