Display Group help

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)

Gonna bump to post up, I really need help on this.

I am not sure what you are trying to do with the ‘rect’ or ‘rect group’ on the right side of he screen.  I think I see what you are doing with increasing the number of zombies as each level increases…   but the rect thing I do not understand the purpose of that.

So my ‘GUESS’ is for a quick fix is maybe ‘remark’ line #74  where you continually creating rects every frame.  That might get the app to do what you want it to.  But that is based on my ‘GUESS’ I think remarking out line #74 will work. 

BUT, I see a big issue with lines #75,#76 … it makes no sense to me to ‘remove’ and immediately  ‘add’ the game loop listener inside the game loop as you are doing.  I am not familiar with the ‘finalize’ event.  I have never used it (probably I should), but I am just not familiar with it.  So I have no idea how that works in synch or not with the gameLoop.

So my comment is that maybe you need to really  break your code down and get an strong understanding of the events.  I think line #75 and #76 are very taxing on the processor.

Good Luck

Bob

Gonna bump to post up, I really need help on this.

I am not sure what you are trying to do with the ‘rect’ or ‘rect group’ on the right side of he screen.  I think I see what you are doing with increasing the number of zombies as each level increases…   but the rect thing I do not understand the purpose of that.

So my ‘GUESS’ is for a quick fix is maybe ‘remark’ line #74  where you continually creating rects every frame.  That might get the app to do what you want it to.  But that is based on my ‘GUESS’ I think remarking out line #74 will work. 

BUT, I see a big issue with lines #75,#76 … it makes no sense to me to ‘remove’ and immediately  ‘add’ the game loop listener inside the game loop as you are doing.  I am not familiar with the ‘finalize’ event.  I have never used it (probably I should), but I am just not familiar with it.  So I have no idea how that works in synch or not with the gameLoop.

So my comment is that maybe you need to really  break your code down and get an strong understanding of the events.  I think line #75 and #76 are very taxing on the processor.

Good Luck

Bob