In my project; when the white circle is hold on, the number of zombies is decreased by one. When the number of zombies reach zero, the wave number is increased by one. and the number of zombies are then equal to the number of waves. While that happens, a rectangle at the side is created after the wave value is increased by one.
However, my problem is that the rectangles are constantly being made in the same place where the second rectangle was created and that rectangles are being creating when the wave hasn’t changed.
If you still don’t understand, just paste the code in and you will understand.
Here is my code:
local wave = 1 local zombies = wave local rectGroup = display.newGroup() local rect = display.newRect(rectGroup,display.contentCenterX+90,display.contentCenterY,50,400) local function moveup() zombies=zombies-1 rectGroup.y=rectGroup.y+5 end local needToup = false local function handleEnterFrame( event ) if ( needToup == true ) then moveup() end end Runtime:addEventListener( "enterFrame", handleEnterFrame ) local function handleupButton( event ) if ( event.phase == "began" ) then -- Fire the weapon needToup = true elseif ( event.phase == "ended" and needToup == true ) then -- Stop firing the weapon needToup = false end return true end local circleup = display.newCircle(display.contentCenterX,display.contentCenterY,40) circleup:addEventListener("touch",handleupButton) local waveText = display.newText(wave, display.contentCenterX, 100, native.systemFontBold, 25) local waveTitle = display.newText("Wave:", waveText.x, waveText.y-20, native.systemFontBold, 25) local zombiesText = display.newText(zombies, display.contentCenterX, 175, native.systemFontBold, 25) local zombiesTitle = display.newText("Zombies:", zombiesText.x, zombiesText.y-20, native.systemFontBold, 20) function zombiesText.enterFrame( self ) self.text = tostring(zombies) end Runtime:addEventListener("enterFrame", zombiesText ) function zombiesText.finalize( self ) Runtime:removeEventListener( "enterFrame", self ) end zombiesText:addEventListener("finalize") function waveText.enterFrame( self ) self.text = tostring(wave) end Runtime:addEventListener("enterFrame", waveText ) function waveText.finalize( self ) Runtime:removeEventListener( "enterFrame", self ) end waveText:addEventListener("finalize") local function gameLoop() if zombies==0 then wave=wave+1 zombies=wave end if wave\>1 then print("On wave"..tostring(wave)) display.newRect(rectGroup,display.contentCenterX+90,-rectGroup[rectGroup.numChildren].y+70,50,400) Runtime:removeEventListener("enterFrame", gameLoop) Runtime:addEventListener("enterFrame", gameLoop) end end Runtime:addEventListener("enterFrame", gameLoop)