2012-07-23 33 views
3

我必須構建一個賽車遊戲。爲此,我使用道路作爲背景,我需要向下滾動並重復,以便屏幕始終顯示移動的道路,即相對於用戶車輛,道路看起來正在移動。在電暈sdk中設計無盡的滾動背景

回答

2

只是爲了將來的參考,這裏是一個垂直滾動背景代碼:

local function moveBg(dt) 
    bg1.y = bg1.y + scrollSpeed * dt 
    bg2.y = bg2.y + scrollSpeed * dt 
    if (bg1.y - display.contentHeight/2) > display.actualContentHeight then 
     bg1:translate(0, -bg1.contentHeight * 2) 
    end 
    if (bg2.y - display.contentHeight/2) > display.actualContentHeight then 
     bg2:translate(0, -bg2.contentHeight * 2) 
    end 
end 

而完整的教程是在這裏:http://lomza.totem-soft.com/tutorial-scrollable-background-in-corona-sdk/