1

私は水槽を作成しています..だから私がしたいのは、私の魚が無限にスクロールすることです..私はアクションスクリプト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;
}
}

f1 と f2 は私の魚のインスタンス名です

4

2 に答える 2

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;
}
于 2013-07-08T10:50:13.630 に答える
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;
}

これらは基本的な例にすぎませんが、アイデアは理解できます

于 2013-07-08T08:57:16.143 に答える