[英]AS3 programming animation loop problems
我正在努力使对象从左侧移到右侧一定距离,然后从左侧开始一遍又一遍。
我很好奇它是如何工作的。 目前,我有这个(简化的)代码,其中“ rect”应该在右侧循环:
ok, this is the code non simplified: function preload(e:Event):void{
var loadedBytes=loaderInfo.bytesLoaded;
var totalBytes=loaderInfo.bytesTotal;
var rect=MovieClip(root).loader_rect;
var startpos=rect.x=stage.x-rect.width;
if(loadedBytes==totalBytes){
removeEventListener(Event.ENTER_FRAME, preloader);
gotoAndStop(2);
}
else{
rect.x+=3.5+loadedBytes/totalBytes;
if(rect.x>=stage.x+stage.width) rect.x=startpos
else rect.x+=3.5+loadedBytes/totalBytes;
}
} (I get no errors, just the animation isn't working)
在我看来,应该掩盖它。 如果rect的位置大于200,则将其移至0,否则在每帧上向右移10px。 但是它所做的只是向右右移动几个像素然后停止。 为什么这样不起作用,逻辑不正确吗?
下面的代码行重置 rect
对象的x位置:
var startpos = rect.x = stage.x - rect.width;
这意味着在每一帧上, rect
都移到上面的位置,然后向右移动3.5 + 0到1像素之间的小数 。 然后,它将向右移动额外的 3.5 + 0到1像素之间的小数 。
因此,在每一帧上, rect
对象都将移动到x的位置
stage.x - rect.width + 3.5 * 2 + [percent loaded] * 2
因此, rect
将永远不会移动太多(在加载过程中最多2个像素)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.