2014-02-16 27 views
1

我有一個程序,其中流星落在一個角色,並在7號線電暈模擬器拋出錯誤「試圖索引本地的背景」(一個零值)「我不知道是什麼造成這種情況,並希望有人可以幫助!背景是否爲零值?

Relavent代碼:

--Start the physics engine! 
local physics = require ("physics") 

--Get a background image! 
local screen_adjustment = 1 
local background = display.newImage("Images/Background", true) 
background.xScale = (screen_adjustment*background.contentWidth)/background.contentWidth 
background.yScale = background.xScale 
background.x = display.contentWidth/2 
background.y = display.contentHeight/2 

回答

0

您的圖像爲零,因爲它無法創建它。仔細檢查你的文件名和路徑。你忘記Background.png的擴展名了嗎?

1

display.newImage回報nil。很可能是因爲你沒有一個名爲Images/Background的文件。

1

給定給display.newImage的文件名假定(默認情況下)駐留在應用程序資源目錄中,該目錄與包含您的main.lua的文件夾相同。因此,您的代碼假設在包含main.lua的文件夾中有一個名爲Images的文件夾,並在其中包含一個名爲Background的文件。您還必須提供擴展名,例如Background.png