Actionscript 3 如何在action script3中创建无限滚动动画

Actionscript 3 如何在action script3中创建无限滚动动画,actionscript-3,flash,flash-cs6,Actionscript 3,Flash,Flash Cs6,我正在创建一个鱼缸。所以我想做的是我的鱼应该是无限滚动的。我正在使用动作脚本3。这是我使用的代码。但是它不起作用 var scrollSpeed:uint = 5; //This adds two instances of the movie clip onto the stage. //This positions the second movieclip next to the first one. f1.x = 0; f2.x = f1.width; //Adds an even

我正在创建一个鱼缸。所以我想做的是我的鱼应该是无限滚动的。我正在使用动作脚本3。这是我使用的代码。但是它不起作用

var scrollSpeed:uint = 5;

//This adds two instances of the movie clip onto the stage.



//This positions the second movieclip next to the first one.
f1.x = 0;
f2.x = f1.width;

//Adds an event listener to the stage.
stage.addEventListener(Event.ENTER_FRAME, moveScroll); 

//This function moves both the images to left. If the first and second 
//images goes pass the left stage boundary then it gets moved to 
//the other side of the stage. 
function moveScroll(e:Event):void{
f1.x -= scrollSpeed;  
f2.x -= scrollSpeed;  

if(f1.x < +f1.width){
f1.x = f1.width;
}else if(f2.x < +f2.width){
f2.x = f2.width;
}
}
var滚动速度:uint=5;
//这将在舞台上添加两个电影剪辑实例。
//这将第二个movieclip定位在第一个movieclip的旁边。
f1.x=0;
f2.x=f1.1宽度;
//将事件侦听器添加到阶段。
stage.addEventListener(Event.ENTER_FRAME,moveScroll);
//此函数将两个图像向左移动。如果第一个和第二个
//图像通过左舞台边界,然后移动到
//舞台的另一边。
功能移动滚动(e:事件):无效{
f1.x-=滚动速度;
f2.x-=滚动速度;
如果(f1.x<+f1.宽度){
f1.x=f1.x宽度;
}否则如果(f2.x<+f2.宽度){
f2.x=f2.1宽度;
}
}

f1和f2是我的fish实例名称

这假设您的图像/mc足够大,可以在屏幕上显示,并且是重复的(具有相同的内容)

函数移动滚动(e:事件):无效{
//定位鱼1
f1.x-=滚动速度;
//当鱼1超出边界时(离开左侧屏幕,将其设置回0
如果(f1.x<-f1.宽度){
f1.x=0;
}
//始终将鱼2放在鱼1旁边
f2.x=f1.x+f1.x宽度;
}
另一种方法是将它们放在一个数组中,如果它们的内容不相同,则进行切换:

//add fishes to array
var images:Array = new Array();
images.push(f1, f2);

function moveScroll(e:Event):void {
    //position fish 1
    images[0].x -= scrollSpeed;
    //when first fish is out of bounds, remove it from the array (unshift) and add it at the end (push)
    if (images[0].x < -images[0].width) {
       images.push(images.unshift())
    }
    //always position fish2 next to fish 1
    images[1].x = images[0].x + images[0].width;
}
//将鱼添加到数组
变量图像:数组=新数组();
图像。推送(f1,f2);
功能移动滚动(e:事件):无效{
//定位鱼1
图像[0]。x-=滚动速度;
//当第一条鱼超出边界时,将其从阵列中移除(取消移动),并将其添加到末端(推)
if(图像[0].x<-images[0].宽度){
images.push(images.unshift())
}
//始终将鱼2放在鱼1旁边
图像[1]。x=图像[0]。x+图像[0]。宽度;
}

这些只是一些基本的例子,但是你得到了一个想法

这假设你的图像/mc足够大,可以放在屏幕上,并且是重复的(具有相同的内容)

函数移动滚动(e:事件):无效{
//定位鱼1
f1.x-=滚动速度;
//当鱼1超出边界时(离开左侧屏幕,将其设置回0
如果(f1.x<-f1.宽度){
f1.x=0;
}
//始终将鱼2放在鱼1旁边
f2.x=f1.x+f1.x宽度;
}
另一种方法是将它们放在一个数组中,如果它们的内容不相同,则进行切换:

//add fishes to array
var images:Array = new Array();
images.push(f1, f2);

function moveScroll(e:Event):void {
    //position fish 1
    images[0].x -= scrollSpeed;
    //when first fish is out of bounds, remove it from the array (unshift) and add it at the end (push)
    if (images[0].x < -images[0].width) {
       images.push(images.unshift())
    }
    //always position fish2 next to fish 1
    images[1].x = images[0].x + images[0].width;
}
//将鱼添加到数组
变量图像:数组=新数组();
图像。推送(f1,f2);
功能移动滚动(e:事件):无效{
//定位鱼1
图像[0]。x-=滚动速度;
//当第一条鱼超出边界时,将其从阵列中移除(取消移动),并将其添加到末端(推)
if(图像[0].x<-images[0].宽度){
images.push(images.unshift())
}
//始终将鱼2放在鱼1旁边
图像[1]。x=图像[0]。x+图像[0]。宽度;
}

这些只是一些基本的例子,但是你得到的想法是你的问题线在底部

if (f1.x < f1.width) {
    f1.x = stage.stageWidth - f1.width // f1.width;
} // Removed else

if (f2.x < f2.width) {
    f2.x = f1.width;
}
if(f1.x
您的问题列在底部

if (f1.x < f1.width) {
    f1.x = stage.stageWidth - f1.width // f1.width;
} // Removed else

if (f2.x < f2.width) {
    f2.x = f1.width;
}
if(f1.x
我有点困惑,你想在鱼离开一侧后将你的鱼移到屏幕的另一侧吗?我有点困惑,你想在鱼离开一侧后将你的鱼移到屏幕的另一侧吗?