2013-05-14 48 views
0

,我發現了錯誤:錯誤:試圖指數全局對象一個零值:電暈SDK

運行時錯誤 ......正stylr \文件\電暈項目\ happy_day \ game.lau:50 :試圖指數全球 'city1'(一個零值)

我的代碼如下:

function scene:createScene(event) 

local screenGroup = self.view 

local background = display.newImage("background1.jpg") 

local city1 = display.newImage("bild.png") 
city1:setReferencePoint(display.BottomLeftReferencePoint) 
city1.x = 0 
city1.y = 640 
city1.speed = 1 

local city2 = display.newImage("bild.png") 
city2:setReferencePoint(display.BottomLeftReferencePoint) 
city2.x = 1136 
city2.y = 640 
city2.speed = 1 

local city3 = display.newImage("build2.png") 
city3:setReferencePoint(display.BottomLeftReferencePoint) 
city3.x = 0 
city3.y = 640 
city3.speed = 2 

local city4 = display.newImage("build2.png") 
city4:setReferencePoint(display.BottomLeftReferencePoint) 
city4.x = 1136 
city4.y = 640 
city4.speed = 2 
end 

function scene:enterScene(event) 

Runtime:addEventListener("touch", touchScreen) 
print(city1) 
city1.enterFrame = scrollCity 
Runtime:addEventListener("enterFrame", city1) 

city2.enterFrame = scrollCity 
Runtime:addEventListener("enterFrame", city2) 

city3.enterFrame = scrollCity 
Runtime:addEventListener("enterFrame", city3) 

city4.enterFrame = scrollCity 
Runtime:addEventListener("enterFrame", city4) 

end 
+3

請給你的問題一個方便的標題。大多數人問這裏有一個問題,並找不到解決方案。 – kelunik

回答

1

只是聲明local city1createScene功能外,並創建city1爲:

local city1; 

function scene:createScene(event) 
    -- your code for localGroup and bg 

    city1 = display.newImage("bild.png") -- just create city1 as this 

    -- do the rest of your code 
end 

如果錯誤發生時要重新考慮其他城市(city2,3或4),請對所有這些方法執行相同的方法。

保留編碼................ :)

相關問題