電暈

2011-11-01 95 views
7

我開發電暈一個應用程序,我需要再次重新加載相同的屏幕和again.I沒有任何想法,如何做到這一點,重裝屏幕誰能給我解釋一下這一個代碼電暈

回答

3

1)director class

2)main.lua

display.setStatusBar (display.HiddenStatusBar) 
--> Hides the status bar 

local director = require ("director") 
--> Imports director 

local mainGroup = display.newGroup() 
--> Creates a main group 

local function main() 
--> Adds main function 

    mainGroup:insert(director.directorView) 
    --> Adds the group from director 

    director:changeScene("myscene") 
    --> Change the scene, no effects 

    return true 
end 

main() 

3)myscene.lua

module(..., package.seeall) 

function new() 
    local localGroup = display.newGroup() 

    local redbutton = display.newImage ("redbutton.png") 
    redbutton.x = 160 
    redbutton.y = 100 
    localGroup:insert(redbutton) 

    local function pressRed (event) 
     if event.phase == "ended" then 
      director:changeScene ("reloader") 
     end 
    end 

    redbutton:addEventListener ("touch", pressRed) 

    return localGroup 
end 

4)reloader.lua

module(..., package.seeall) 

function new() 
    local localGroup = display.newGroup() 

     local function listener(event) 
      director:changeScene ("myscene", "fade") 
     end 

     timer.performWithDelay(50, listener) 

     return localGroup 
end 
1

故事板API是因爲構建可用2011.678

下面是使用利用故事板API的示例建立2011.704

每一觸摸將刷新整個場景

--main.lua 
module(...,package.seeall) 
local storyboard=require("storyboard") 
local scene=storyboard.newScene() 
scene.name="scnMenu" 

function scene:createScene(event) 
    local group=self.view 
    bg=display.newRect(0,0,100,100) 
    group:insert(bg) 
end 


function scene:enterScene(event) 
    Runtime:addEventListener("touch",onTouch) 
end 

function onTouch(event) 
    storyboard.gotoScene("main","fade",1000) 
end 

function scene:exitScene(event) 
    Runtime:removeEventListener("touch",onTouch) 
end 

function scene:destroyScene(event) 
end 

scene:addEventListener("createScene",scene) 
scene:addEventListener("enterScene",scene) 
scene:addEventListener("exitScene",scene) 
scene:addEventListener("destroyScene",scene) 

return scene 
1

我不知道,但我的遊戲我使用相同的lua文件changeScene。

myscene.lua

導演:changeScene( 「myscene」)

0

我已經試過這爲我工作的另一種方法,例如在下面給出 -

第1步 - 創建一個對象 - 本地reloadScene

步驟2-應用步驟2,當需要重新加載場景時 - reloadScene =「YES 「 storyboard.reloadScene(」 eventsButtonClicked「)

步驟3-步驟3應用中,當沒有必要重新加載場景的 - 功能scene2a:exitScene(事件) 如果reloadScene == 」YES「,那麼 storyboard.purgeScene ( 「eventsButtonClicked」) reloadScene = 「NO」 結束 結束 scene2a:的addEventListener( 「exitScene」,scene2a)

0

我想你應該按照此步驟:我已經重新加載執行/重啓故事板在日冕中的場景。

第1步:創建一個函數或一行代碼重新/重新加載相同的場景從想要重新加載或重新啓動的故事板類。

function forRestart(event) 

if(event.phase == "ended") then 

    local current_scene_name = storyboard.getCurrentSceneName() 
    **storyboard.gotoScene("reload", "fade", 250)** 

return true; 
end 

第2步:創建一個名爲重裝一個LUA文件。以下是reload.lua文件的模板。

local storyboard = require("storyboard") 
local scene = storyboard.newScene() 

-- Called when the scene's view does not exist: 
function scene:createScene(event) 
    local group = self.view 

end 

- 現場後立即調用移動屏幕上:

function scene:enterScene(event) 
    local group = self.view 
    --purge level 
    local previous_scene_name = storyboard.getPrevious() 
    print("previous",previous_scene_name) 
    --storyboard.removeScene(previous_scene_name) 
    storyboard.purgeScene(previous_scene_name) 
    --go back to level, by loading it from scratch 
    storyboard.gotoScene(previous_scene_name, "fade", 250) 
end 

- 當現場將要移動屏幕外的調用:

function scene:exitScene(event) 
    local group = self.view 
end 

- 如果場景的觀點被刪除,場景:destroyScene()將在之前被調用:

function scene:destroyScene(event) 
     local group = self.view 
    end 


-- "createScene" event is dispatched if scene's view does not exist 

    scene:addEventListener("createScene", scene) 


-- "enterScene" event is dispatched whenever scene transition has finished 

    scene:addEventListener("enterScene", scene) 


-- "exitScene" event is dispatched whenever before next scene's transition begins 
scene:addEventListener("exitScene", scene) 

-- "destroyScene" event is dispatched before view is unloaded, which can be 
-- automatically unloaded in low memory situations, or explicitly via a call to 
-- storyboard.purgeScene() or storyboard.removeScene(). 
scene:addEventListener("destroyScene", scene) 

return scene 
0

您也可以使用此方法重新加載相同的屏幕: timer.performWithDelay(500,function()director:changeScene(「your scene name」)); 但在調用上述函數之前,您需要從顯示組中刪除所有對象。

0

您可以創建一個重新載入場景, 並調用Roload的任何場景。 像這樣

composer.gotoScene("Scene.Reload" , 
    { 
     params = 
     { 
      reloadSceneOptions = 
      { 
       effect = "slideLeft", 
       time = 500, 
      }, 
      reloadSceneName = SceneName 
     } 
    }) 

和你刷新場景類似的代碼

elseif phase == "did" then 
    local reloadSceneOptions = event.params.reloadSceneOptions 
    local reloadSceneName = event.params.reloadSceneName 

    composer.removeScene(reloadSceneName) 
    composer.gotoScene(reloadSceneName , reloadSceneOptions) 
end