我正在處理的項目有一個巨大的背景圖像(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;
}
}
嗨!你所建議的編輯並沒有修復這個錯誤 - 在兩次迭代之後,它仍然會增加一行或兩行空格。他似乎沒有在演示頁面上遇到同樣的問題 - 我用完整的代碼更新了我的問題。 – aendrew 2011-02-08 07:14:31
另外,我在這兩個條件語句中減去了scrollSpeed的值 - 看起來這個錯誤發生在一次迭代之後。我猜這個空間恰好是scrollSpeed的數量。 – aendrew 2011-02-08 07:37:52