我正在修修补补,让一个物体从左边移动到右边一定的距离,然后一遍又一遍地从左边重新开始。
我很好奇它是如何工作的。目前我有这个(简化的)代码,其中'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向右移动几个像素,然后停止。为什么这个不起作用,逻辑是不是不正确?
发布于 2014-07-02 20:47:16
下面的代码行重置rect对象的x位置:
var startpos = rect.x = stage.x - rect.width; 这意味着在每一帧上,rect被移动到上面的位置,然后向右移动3.5 +0到1像素之间的分数。然后,它将被向右移动一个额外的 3.5 +0到1像素之间的分数。
因此,在每一帧上,rect对象都将被移动到
stage.x - rect.width + 3.5 * 2 + [percent loaded] * 2因此,rect看起来不会移动太多(在加载过程中最多移动2个像素)。
https://stackoverflow.com/questions/24527462
复制相似问题