在场景变化CoronaSDK Storyboard中不会删除表格

时间:2013-07-27 23:40:59

标签: lua corona scene lua-table corona-storyboard

基本上,我有一个水平移动的图像表,当我更改它停留在那里的场景时,即使我没有调用它。就像在,在offlinemode.lua中没有代码。我认为由于某种原因,这是一个全球因素..

这是main.lua:

    local storyboard = require "storyboard"
    local options =
    {
        effect = "slideLeft",
        time = 800
    }
    storyboard.gotoScene( ".Lua.MainMenu", options )

This MainMenu.lua

--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
--/////// Unamed game (so far) main.lua is GUI/MENU
--            ////////////////////////////////////////////////////////////////////////////////////////////    //////////////////////////////////////////////
--implements the storybord then deletes it upon completeion--
local storyboard = require "storyboard"
storyboard.purgeOnSceneChange = true
--You may began now-- (incorrectly speeleed corrctly)
local scene = storyboard.newScene()

--makes a container for the background--
-- createScene event simply creates a background image
function scene:createScene( event )
local bg = display.newImage( self.view, "background.png" )
end
scene:addEventListener( "createScene" )
--end of aking a container for the background--

--disables the status bar--
display.setStatusBar( display.HiddenStatusBar ) 
--end of disabling of status bar--

--Returns Screen Width and Screen Height--
_W = display.contentWidth; 
_H = display.contentHeight;
--end of returning screen width and height--


--////////////////////////////////////////////////end of the background\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\--
--**********************************************************************************************************************--

--////////////////////////////////////////////////Menu Buttons\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\--
--Set up a local container for the buttons--
local widget = require( "widget" )
local PlayBtn

local function onPlayBtnRelease()

    -- go to level1.lua scene
    storyboard.gotoScene( ".Lua.offlinemode", "slideLeft", 500 )
    display.remove(initstar)
    return true -- indicates successful touch
end
    local PlayBtn = widget.newButton
{
   left = 160,
   top = 80,
   label = "Offline",
   labelAlign = "center",
   font = "Arial",
   fontSize = 18,
   labelColor = { default = {0,0,0}, over = {255,255,255} },
   onRelease = onPlayBtnRelease
  }
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
--********************************************************************************************************************--
--///////////////////////////////////////Setting up         background\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\--
--set up the table to store the clouds in--
    local starTable = {}
--end of the table to store the clouds in--

--creates three containers with a picture of a cloud--
function initStar()
    local star1 = {}
    star1.imgpath = "/images/Cloud1.png"; --Set Image Path for Star
    star1.movementSpeed = 10000; --Determines the movement speed of star
    table.insert(starTable, star1); --Insert Star into starTable

    local star2 = {}
    star2.imgpath = "/images/cloud2.png";
    star2.movementSpeed = 12000;
    table.insert(starTable, star2);             

    local star3 = {}
    star3.imgpath = "/images/cloud3.png";
    star3.movementSpeed = 14000;
    table.insert(starTable, star3);
end
--ends the function--

--Gets random stars from the table, positioning them randomly--
function getRandomStar()
    local temp = starTable[math.random(1, #starTable)] -- Get a random star from                 starTable
    local randomStar = display.newImage(temp.imgpath) -- Set image path for object
    randomStar.myName = "star" -- Set the name of the object to star
    randomStar.movementSpeed = temp.movementSpeed; -- Set how fast the object will move
    randomStar.y = math.random(10,_H) -- Set starting point of star at a random X position
    randomStar.x = -40; -- Start the star off screenm
    starMove = transition.to(randomStar, { --Move the Clouds
        time=randomStar.movementSpeed, --sets the speed relative to it's lifetime
        onComplete = function(self) self.parent:remove(self); self = nil; end, --        removes itself
        x=500 --speed of ?
        }) -- Move the Clouds
end
--The end of this function--

--Starts the timer before the Clouds "spawn"--
function startGame()
        starTimer1 = timer.performWithDelay(1070,getRandomStar, 0)
        starTimer2 = timer.performWithDelay(2030,getRandomStar, 0)
        starTimer3 = timer.performWithDelay(2070,getRandomStar, 0)      
end
--ends the function--

initStar()
startGame()
-- "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().
function scene:didExitScene( event )
storyboard.purgeScene( "scene1" )
end
scene:addEventListener( "didExitScene" )
return scene
--end the Online function--

最后是offlinemode.lua:

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local background = display.newImage("background.png")
local image = display.newImage("/images/ButtonStartOffline.png")
function scene:createScene( event )

end

function scene:enterScene( event )

end  

function scene:exitScene( event )

end

function scene:destroyScene( event )

end

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


return scene

如果有效,请告诉我为什么它不适合我..

3 个答案:

答案 0 :(得分:1)

你应该把图像放到createSceneenterScene的显示组中,所以当你去另一个场景时,它会删除那个场景中的所有图像,这里是它的实现看到的代码

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

 --/////////////////////Setting up background\\\\\\\\\\\\\\\\\\--
        --set up the table to store the clouds in--
     local starTable = {}
        --end of the table to store the clouds in--

    --creates three containers with a picture of a cloud--
    function initStar()
        local star1 = {}
        star1.imgpath = "/images/Cloud1.png"; --Set Image Path for Star
        star1.movementSpeed = 10000; --Determines the movement speed of star
        table.insert(starTable, star1); --Insert Star into starTable

        local star2 = {}
        star2.imgpath = "/images/cloud2.png";
        star2.movementSpeed = 12000;
        table.insert(starTable, star2);             

        local star3 = {}
        star3.imgpath = "/images/cloud3.png";
        star3.movementSpeed = 14000;
        table.insert(starTable, star3);
    end
    --ends the function--

    --Gets random stars from the table, positioning them randomly--
    function getRandomStar()
        local temp = starTable[math.random(1, #starTable)] -- Get a random star from                 starTable
        local randomStar = display.newImage(temp.imgpath) -- Set image path for object
        randomStar.myName = "star" -- Set the name of the object to star
        randomStar.movementSpeed = temp.movementSpeed; -- Set how fast the object will move
        randomStar.y = math.random(10,_H) -- Set starting point of star at a random X position
        randomStar.x = -40; -- Start the star off screenm
        group:insert(randomStart) **-- inserting random star into Group**
        starMove = transition.to(randomStar, { --Move the Clouds
            time=randomStar.movementSpeed, --sets the speed relative to it's lifetime
            onComplete = function(self) self.parent:remove(self); self = nil; end, --        removes itself
            x=500 --speed of ?
            }) -- Move the Clouds
    end
    --The end of this function--

    --Starts the timer before the Clouds "spawn"--
    function startGame()
            starTimer1 = timer.performWithDelay(1070,getRandomStar, 0)
            starTimer2 = timer.performWithDelay(2030,getRandomStar, 0)
            starTimer3 = timer.performWithDelay(2070,getRandomStar, 0)      
    end
    --ends the function--

    initStar()
    startGame()


end

答案 1 :(得分:0)

您可以尝试将“randomStar.y = -100”添加到新场景中,但这不会删除它们,但会将它们排除在外。

答案 2 :(得分:0)

scene:addEventListener( "didExitScene") 

应该是:

scene:addEventListener( "didExitScene", scene )

在第一个代码段的最后一部分