I’m developing a game which uses a matrix of square elements.
It’s something like this:
1 2 3 4 5 …
1 X - - A -
2 - X X O X
3 X X A A O
4 O - - - X
5 A A A A A
…
I represent the map as a matrix (actualy 20x20)
Depending on the value, the update screen function show the correct image:
local function update_screen()
for j=1,20 do
for k=1,20 do
if map[j][k]==1 then
display.newImage(“image_X.png”, (j-1)*size, (k-1)*size)
elseif map[j][k]==2 then
display.newImage(“image_O.png”, (j-1)*size, (k-1)*size)
elseif map[j][k]==2 then
display.newImage(“image_A.png”, (j-1)*size, (k-1)*size)
elseif map[j][k]==4 then
display.newImage(“image_-.png”, (j-1)*size, (k-1)*size)
end
end
end
Of course this function creates 20x20=400 image objects even I don’t use variables pointing to them.
As the game advance, the map fields change and I call again and again the update_screen().
So each time, there are more 400 image objects being created, which stay in memory.
I observe that at start point the game is fast and then slow down its speed. (maybe because the raise amount of memory used).
So, I want to remove the whole display in the beginning of the update_screen() function.
How can I do that?
I tried display.remove() and display.remove(display) but don’t work.
Maybe you will tell me to use variables pointing to all 400 objects and then remove them all one by one but I think this is nonsense in this case.
So what can I do to perform what I want?
Help me.
Thanks!