greetings people,
im trying to make a memery game, so i found an example on it and made some adjustments.
the problem is i dont really 100% understand how it works thus it gives me some problems when trying to remove things from the scene
setting up the game goes as follows:
for count = 1,4 do x = x + 100 y = -50 for insideCount = 1,5 do y = y + 150 --Assign each image a random location on grid temp = math.random(1,#buttonImages) button[count] = display.newImage(buttonImages[temp] .. ".png"); --Position the button button[count].x = x; button[count].y = y; --Give each a button a name button[count].myName = buttonImages[temp] button[count].number = totalButtons button[count].id=buttonid[#buttonImages] --Remove button from buttonImages table table.remove(buttonImages, temp) buttonCover[totalButtons] = display.newImage("button.png"); buttonCover[totalButtons].x = x; buttonCover[totalButtons].y = y; buttonCover[totalButtons].width=100 buttonCover[totalButtons].height=100 totalButtons = totalButtons + 1 button[count].touch = game button[count]:addEventListener( "touch", button[count] ) button[count].width=100 button[count].height=100 end end
removing the buttonCover goes easy enough but its the removal of the buttons that gives me struggle.
i try to remove both this way
local function handleButtonEvent2( event ) if ( "ended" == event.phase ) then if (event.target.id == "backbtn") then button5.alpha=0 for lul=1,4 do button[lul]:removeSelf( ) button[lul]=nil end for lal=0,20 do if (buttonCover[lal]==nil) then print("buttonCover"..lal.. "was nil") else buttonCover[lal]:removeSelf( ) buttonCover[lal]=nil end end table.remove( buttonCover) table.remove( button) end end end
my question is, how to i remove all 20 buttons as there is only button[count] to 4
is there 5 buttons inside each button[count]??
if so how to i remove it? if not how is it then stored?