I am tring now again to resolve it, i am on my main menu, i only have widget buttons with the respective functions of each button, ice library, one some images and nothing more, and i using my librarys like director, ice on my main.lua and i am using it with this code…
require(“director”)
require(“ice”)
it is not wrong?
or i should use
local director = require (“director”)
local ice = require (“ice”)
what i should use? and for the widget library i am using
local widget = require (“widget”)
i need to use this code each file that i use widget buttons, i cant put this code only one time on my main.lua and then run widget button on my main menu, if i want to run widget buttons on main menu i need to put this code on the main menu too.
maybe it can be increasing my memory usage each time that i switch between two different screens? i am removing my localgroup and i tried to put localgroup = ni, i dont know if it can clean some memory or no, but i didnt see any effect using that.
and i tried on a different project, only with three files.
main.lua
mainmenu.lua
game.lua
and put only a widget button on the mainmenu.lua and on game.lua, and then will changing the screen by pressing on the button, and it will increasing my memory usage each time that i change the screen. the code is:
main.lua
-- Remove head bar
display.setStatusBar( display.HiddenStatusBar)
-- Screen
\_W = display.contentWidth
\_H = display.contentHeight
-- Load librarys
local director = require("director")
-- Create a main group
local MainGroup = display.newGroup();
-- Main function
local function Main()
local function monitorMem(event)
collectgarbage("collect")
print( "\nMemUsage: " .. (collectgarbage("count")/1000) .. " MB")
print("Texture Usage " .. system.getInfo( "textureMemoryUsed" ) / 1000000)
return true
end
Runtime:addEventListener("enterFrame", monitorMem)
MainGroup:insert(director.directorView)
director:changeScene("mainmenu")
return true
end
Main()
mainmenu.lua
module(..., package.seeall)
function new()
local LocalGroup = display.newGroup();
local widget = require "widget"
local PlayTouch = function( event )
LocalGroup:remove()
LocalGroup = nil
director:changeScene("game")
end
local PlayButton = widget.newButton{
default = "play\_button.png",
over = "play\_button\_clicked.png",
onRelease = PlayTouch
}
PlayButton.x = math.round(\_W\*0.5)
PlayButton.y = math.round(\_H\* 0.79)
PlayButton.isVisible = true;
PlayButton.view:toFront();
LocalGroup:insert(PlayButton.view);
return LocalGroup;
end
game.lua
module(..., package.seeall)
function new()
local LocalGroup = display.newGroup();
local widget = require "widget"
local PlayTouch = function( event )
LocalGroup:remove()
LocalGroup = nil
director:changeScene("mainmenu")
end
local PlayButton = widget.newButton{
default = "play\_button.png",
over = "play\_button\_clicked.png",
onRelease = PlayTouch
}
PlayButton.x = math.round(\_W\*0.5)
PlayButton.y = math.round(\_H\* 0.5)
PlayButton.isVisible = true;
PlayButton.view:toFront();
LocalGroup:insert(PlayButton.view);
return LocalGroup;
end
[import]uid: 26056 topic_id: 22128 reply_id: 88699[/import]