Hi!!
I’m just starting with Corona SDK. I’m trying to do a memory game to practice and I am following the tutorial mobiletuts (http://mobile.tutsplus.com/tutorials/corona/corona-sdk-create-a-memory-match-game/?search_index=1)
The problem I have is that I want to hide all elements and when I try to hide the buttonCover array or put it in a group does not work. I don’t know why it doesn’t work.
I want to do something like:
group: insert (buttonCover []) or buttonCover []. alpha = 0
My full code is:
--Set Global width and height variables \_W = display.contentWidth; \_H = display.contentHeight; --Declare a totalButtons variable to track number of buttons on screen totalButtons = 0 -- CREO EL GRUPO DE LA PANTALLA grupo = display.newGroup() --Declare variable to track button select secondSelect = 0 checkForMatch = false --Declare button, buttonCover, and buttonImages table button = {} buttonCover = {} buttonImages = {1,1, 2,2, 3,3, 4,4, 5,5, 6,6, 7,7, 8,8} --Declare and prime a last button selected variable lastButton = display.newImage("imagenes/1.png"); lastButton.myName = 1; grupo:insert(lastButton) --Set up simple off-white background myRectangle = display.newRect(0, 0, \_W, \_H) myRectangle:setFillColor(235, 235, 235) grupo:insert(myRectangle) --Notify player if match is found or not matchText = display.newText(" ", 0, 0, native.systemFont, 26) matchText:setReferencePoint(display.CenterReferencePoint) matchText:setTextColor(0, 0, 0) matchText.x = \_W/2 grupo:insert(matchText) --Set starting point for button grid x = -20 --FUNCIONAMIENTO DEL JUEGO function game(object, event) if(event.phase == "began") then if(checkForMatch == false and secondSelect == 0) then --Flip over first button buttonCover[object.number].isVisible = false; lastButton = object checkForMatch = true elseif(checkForMatch == true) then if(secondSelect == 0) then --Flip over second button buttonCover[object.number].isVisible = false; secondSelect = 1; --If buttons do not match, flip buttons over if(lastButton.myName ~= object.myName) then matchText.text = "Match Not Found!"; timer.performWithDelay(1250, function() matchText.text = " "; checkForMatch = false; secondSelect = 0; buttonCover[lastButton.number].isVisible = true; buttonCover[object.number].isVisible = true; end, 1) --If buttons DO match, remove buttons elseif(lastButton.myName == object.myName) then matchText.text = "Match Found!"; timer.performWithDelay(1250, function() matchText.text = " "; checkForMatch = false; secondSelect = 0; lastButton:removeSelf(); object:removeSelf(); buttonCover[lastButton.number]:removeSelf(); buttonCover[object.number]:removeSelf(); end, 1) end end end end end --IMAGENES EN PANTALLA for count = 1,4 do x = x + 70 y = 20 for insideCount = 1,4 do y = y + 90 --Assign each image a random location on grid temp = math.random(1,#buttonImages) button[count] = display.newImage("imagenes/" .. 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 --Remove button from buttonImages table table.remove(buttonImages, temp) --Set a cover to hide the button image buttonCover[totalButtons] = display.newImage("imagenes/button.png"); buttonCover[totalButtons].x = x; buttonCover[totalButtons].y = y; totalButtons = totalButtons + 1 --Attach listener event to each button button[count].touch = game button[count]:addEventListener( "touch", button[count] ) grupo:insert(button[count]) end end grupo.alpha = 0