Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Creating a Group and how to unload? - Gideros Forum

Creating a Group and how to unload?

MillerszoneMillerszone Member
edited September 2011 in General questions
I'm not very experienced with Lua, so I have a question about Creating a Group and
how to unload with Gideros. I know how to create a Group and upload with Corona.

Corona example:
-- Main menu screen
 
-- Create menu group
local menuGroup = display.newGroup() 
 
-- Display menu screen
local menuBG = display.newImageRect("menu.png", 480, 320)
menuGroup:insert(menuBG)
 
-- New game button
newGameBTN = display.newImageRect("newgameBtn.png", 270, 36)
menuGroup:insert(newGameBTN)
 
-- Settings button
settingsBTN = display.newImageRect("settingsBtn.png", 270, 36)
menuGroup:insert(settingsBTN)
 
-- Statistics button
statisticsBTN = display.newImageRect("statsBtn.png", 270, 36)
menuGroup:insert(statisticsBTN)
 
-- When I'm ready to unload the main menu I use this:
display.remove(menuGroup); menuGroup = nil
Also is there a way to monitor Memory with Gideros like the cose below?
-- local monitorMem = function()
 
    -- collectgarbage()
    -- print( "\nMemUsage: " .. collectgarbage("count") )
 
    -- local textMem = system.getInfo( "textureMemoryUsed" ) / 1000000
    -- print( "TexMem:   " .. textMem )
-- end
 
-- Runtime:addEventListener( "enterFrame", monitorMem )

Comments

  • atilimatilim Maintainer
    Hi,

    You can use Sprites to group your display objects like:
    -- Main menu screen
     
    -- Create menu group
    local menuGroup = Sprite.new()
    stage:addChild(menuGroup)       -- and add this sprite to stage
     
    -- Display menu screen
    local menuBG = Bitmap.new(Texture.new("menu.png"))
    menuGroup:addChild(menuBG)
     
    -- New game button
    newGameBTN = Bitmap.new(Texture.new("newgameBtn.png"))
    menuGroup:addChild(newGameBTN)
     
    -- Settings button
    settingsBTN = Bitmap.new(Texture.new("settingsBtn.png"))
    menuGroup:addChild(settingsBTN)
     
    -- Statistics button
    statisticsBTN = Bitmap.new(Texture.new("statsBtn.png"))
    menuGroup:addChild(statisticsBTN)
     
    -- When I'm ready to unload the main menu I use this:
    stage:removeChild(menuGroup); menuGroup = nil

    Currently, it's not possible to get the used texture memory but you can get the memory that Lua allocates:
    local monitorMem = function()
        collectgarbage()
        print( "\nMemUsage: " .. collectgarbage("count") )
    end
     
    stage:addEventListener(Event.ENTER_FRAME, monitorMem)
  • I have to get use to the "Sprite" class. I think Sprite is like Display in Corona.

    Thank atilim!
Sign In or Register to comment.