This code works fine and reports 0 texture memory until I add a Default.png to the
folder. It seems to be linked some how to the event. Is there a way to clear the
Default.png from texture memory after the game has loaded or am I doing something
else wrong.
I used the fish images. Code is not Beautified 
[code]
local map = {}
for x=1,8 do
map[x] = {}
for y=1,10 do
map[x][y]={}
end
end
local restart=0
local function gameEventLoop(event)
if restart==1 then
loadMap()
restart=0
end
end
function onTouch( event)
print(“touch restart”)
local t = event.target
local phase = event.phase
if “began” == phase then
– Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )
t.isFocus = true
elseif t.isFocus then
if “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
–loadMap()
restart=1
end
end
return true
end
function destroyMap()
for x=1,8 do
for y=1,10 do
if (map[x][y].image~= “blank”) then
if (map[x][y].button~=nil) then
map[x][y].button:removeEventListener( “touch”, onTouch )
map[x][y].button:removeSelf()
map[x][y].button=nil
end
if (map[x][y].shadow~=nil) then
map[x][y].shadow:removeSelf()
map[x][y].shadow=nil
end
end
end
end
if (map.imagegroup~=nil) then
print("imagegroup "…map.imagegroup.numChildren)
for i=map.imagegroup.numChildren,1,-1 do
local child = map.imagegroup[i]
child.parent:remove( child )
end
end
map.imagegroup=nil
collectgarbage(“collect”)
print(collectgarbage(“count”))
print( “TextureMemory clear: " … system.getInfo(“textureMemoryUsed”) … " bytes” )
end
function loadMap()
destroyMap()
map.imagegroup =display.newGroup()
for x=1,8 do
for y=1,10 do
map[x][y].button = display.newImageRect(“Image1.png”,40,40)
map[x][y].shadow = display.newImageRect(“Image2.png”,40,40)
map[x][y].shadow.alpha=0.5
map.imagegroup:insert(map[x][y].shadow)
map.imagegroup:insert(map[x][y].button)
map[x][y].button.x=(x)*39+5
map[x][y].button.y=(y)*39+46
map[x][y].shadow.x=(x)*39+11
map[x][y].shadow.y=(y)*39+12
map[x][y].button:addEventListener( “touch”, onTouch )
end
end
collectgarbage(“collect”)
print(collectgarbage(“count”))
print( “TextureMemory finished: " … system.getInfo(“textureMemoryUsed”) … " bytes” )
end
loadMap()
loadMap()
loadMap()
Runtime:addEventListener( “enterFrame”, gameEventLoop )
[/code] [import]uid: 8384 topic_id: 3337 reply_id: 303337[/import]