2013-07-08 73 views
1

即時通訊創建一個魚缸..所以我想要做的是我的魚應該是無限滾動..我使用動作腳本3..This是我使用的代碼..但它不是工作..如何在動作腳本中創建一個無限的滾動動畫script3

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; 
} 
} 

f1和f2是我的魚實例名稱

+0

我有點困惑,你是否希望移動魚到屏幕的另一邊後,他們離開一邊? – Glitcher

回答

1

你的問題線在底部。

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

if (f2.x < f2.width) { 
    f2.x = f1.width; 
} 
0

這是假定您的圖片/ MC的是足夠大的屏幕,並且是重複的(具有相同的內容)

function moveScroll(e:Event):void { 
    //position fish 1 
    f1.x -= scrollSpeed; 
    //when fish 1 is out of bounds (off the screen on the left, set it back to 0 
    if (f1.x < -f1.width) { 
     f1.x = 0; 
    } 
    //always position fish2 next to fish 1 
    f2.x = f1.x + f1.width; 
} 

另一種方法是將其放置在一個陣列和交換機在他們身邊,如果他們不具有相同的內容:

//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; 
} 

這些只是基本的例子,但你的想法

相關問題