2011-02-08 77 views
0

我正在處理的項目有一個巨大的背景圖像(800px寬×2585px高),可以向上滾動。在Flash CS5/ActionScript 3中延遲加載無限滾動背景

之前,我使用的代碼:http://www.ilike2flash.com/2010/08/endless-scrolling-background-in-as3.html

我修改代碼來向上滾動,但除了具有奇怪的間歇錯誤圖像之後和循環之前偶爾顯示一個像素高的空白行接下來,它確實似乎無法很好地處理動態加載(我試過使用幾種不同的預加載器腳本,並且它打破了所有這些腳本),這可能不是最初實現時的問題,但現在, m使用巨大的巨大圖像。

因此,我的問題:

a。是否還有一些免費的,基於Flash的無限滾動代碼,它支持延遲加載背景對象(比方說現有的背景切成6)?

b。如果沒有,任何想法如何我可以修改上述鏈接來做到這一點?

謝謝!我的AS3如下:

stop(); 

//The speed of the scroll movement. 
var scrollSpeed:uint = 2; 

//This adds two instances of the movie clip onto the stage. 
var s1:ScrollBg = new ScrollBg(); 
var s2:ScrollBg = new ScrollBg(); 
addChild(s1); 
addChild(s2); 
setChildIndex(s1, 0); 
setChildIndex(s2, 0); 

//This positions the second movieclip next to the first one. 
s1.y = 0; 
s2.y = s1.height; 

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

//This function moves both the images to top. If the first and second 
//images goes past the top stage boundary then it gets moved to 
//the other side of the stage. 
function moveScroll(e:Event):void{ 
    s1.y -= scrollSpeed; 
    s2.y -= scrollSpeed; 

    if(s1.y <= -s1.height){ 
    s1.y = s1.height - scrollSpeed; 
    }else if(s2.y <= -s2.height){ 
    s2.y = s2.height - scrollSpeed; 
    } 
} 

回答

1

你好ændrew 鏈接有大約15行代碼。 它創建了對象的兩個實例,然後它將每個幀都移動1px,並檢查第一個剪輯是否不在視圖中,此時它將movieClip移動到另一個剪輯的邊緣。這裏沒有很多的閃失......但如果我指出來了,我會說這是在這裏

if(s1.x < -s1.width){ 
    s1.x = s1.width; 
}else if(s2.x < -s2.width){ 
    s2.x = s2.width; 
} 

應該是:(注意的<=代替<

if(s1.x <= -s1.width){ 
    s1.x = s1.width; 
}else if(s2.x <= -s2.width){ 
    s2.x = s2.width; 
} 

這將刪除影片剪輯

之間的一些像素差距至於處理加載一個大的資產推移,只需添加滾動功能一旦加載。你可以在http://drawlogic.com/2007/09/20/howto-using-loaders-in-as3/找一個樣品,但也有其他的。

+0

嗨!你所建議的編輯並沒有修復這個錯誤 - 在兩次迭代之後,它仍然會增加一行或兩行空格。他似乎沒有在演示頁面上遇到同樣的問題 - 我用完整的代碼更新了我的問題。 – aendrew 2011-02-08 07:14:31

+1

另外,我在這兩個條件語句中減去了scrollSpeed的值 - 看起來這個錯誤發生在一次迭代之後。我猜這個空間恰好是scrollSpeed的數量。 – aendrew 2011-02-08 07:37:52

0

即時通訊假設你需要一個圓形圖像的寬度/高度,以使其在演示中能夠很好地工作,閃光燈不傾向於渲染.5px間隙等。您可以隨時嘗試將圖像推到位置其他的,只是爲了確保一切正確對接,並希望它呈現更好:

if(s1.x < -s1.width){ 
    s1.x = s2.x + s2.width; 
}else if(s2.x < -s2.width){ 
    s2.x = s1.x + s1.width; 
} 

,當涉及到背景的延遲加載,你需要小心,並檢查下一節圖像已經完成加載,然後開始滾動到它,只是記得將圖像源存儲在var的某個地方(也許是用一個靜態的「延遲加載」類?),所以你試圖多次調用url而不需要。

1

就擺脫了對我的差距此修復程序的「形象之後和在循環的下一個像素高的空白行」 ......

if (s1.x <= - s1.width) { s1.x = s2.x + s2.width; } 
else if (s2.x <= -s2.width) { s2.x = s1.x + s1.width; } 

注意背景的x位置1放置在背景2的x位置加上它的寬度,反之亦然。

0

試試看看Greensock's Blitmask。使用這個,你只需要一個可重複的圖像,並且blitmask被高度優化,即使對於手機功能較弱的處理器也是如此。