0
我嘗試製作一款卡片遊戲,當玩家觸摸卡片時會改變場景,但初始頁面不會再次加載。 我的代碼如下:Corona爲什麼不重新加載場景?
main.lua
local storyboard = require("storyboard")
local background = display.newImage("Icon-72.png")
storyboard.gotoScene("level1")
level1.lua
local storyboard = require("storyboard")
local level1 = storyboard.newScene()
function level1:createScene(event)
print("level 1 create scene")
local group = self.view
local x = 3
group:insert(display.newText(x,40,50))
-- body
local card = display.newImage("Icon-Small.png")
card.x = 50 ; card.y = 150
group:insert(card)
function card:touch(event)
display.remove(card)
storyboard.gotoScene("level2")
end
card:addEventListener("touch",card)
end
function level1:enterScene(event)
local group = self.view
local card = display.newImage("Icon-Small.png")
card.x = 50 ; card.y = 150
group:insert(card)
function card:touch(event)
display.remove(card)
storyboard.gotoScene("level2")
end
card:addEventListener("touch",card)
-- body
end
level1:addEventListener("createScene",level1)
level1:addEventListener("enterScene",level1)
return level1
級別2:
local storyboard = require("storyboard")
local level2 = storyboard.newScene()
function level2:createScene(event)
print("level2 create")
local group = self.view
storyboard.purgeScene("level1")
storyboard.gotoScene("level1")
end
level2:addEventLister("createScene",level2)
return level2
哎呀,是啊,我看出來了,感謝..雖然 – moytas
是打印它並沒有解決的錯誤(「level2的創建」)叫什麼名字? –
yeap..it被調用,然後它會返回到1級,但不會再顯示可點擊的圖像... – moytas