0

基本上,我有一张桌子,上面有水平移动的图像,当我改变场景时,它会留在那里,即使我没有要求它。就像在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

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

4

3 回答 3

1

您应该将图像放在显示组中,createScene这样enterScene当您转到另一个场景时,它将删除该场景中的所有图像这是它的实现,请参见代码

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
于 2013-07-28T13:33:07.020 回答
0
scene:addEventListener( "didExitScene") 

应该 :

scene:addEventListener( "didExitScene", scene )

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

于 2013-07-28T20:41:19.400 回答
0

您能否尝试将“randomStar.y = -100”添加到您的新场景中,这不会删除它们,但会将它们移出视野。

于 2013-07-28T06:52:11.287 回答