Hello -
I have been working on porting one of my games from another language to Corona. So far I’ve managed to do the various scenes and am currently working on the game scene. I’ve done the buttons (widgets), the player’s ship, which rotates, moves forward, wraps around the screen, and fires lasers.
I’m currently having some issues with the lasers. The lasers are fired facing the ship’s rotation, move forward, and wrap around the screen. Where I am currently stuck is in removing the laser. Let’s say the timer for the laser’s removal is 1000ms. If I fire one laser, said laser exists for one second, enough to wrap around y (top) twice with the current parameters. If I fire a second laser within a second’s time (notice the timer value of 1000), the second laser disappears when it reaches the top of the screen; it does not wrap like the other. If I wait a second or more, the next laser will perform like the first one. In other words, a first laser (or laser salvo) will last the 1000ms, but the second laser (or laser salvo) will not make it past a screen edge if fired within 1000ms of the previous laser (or laser salvo).
Any pointers as to what’s wrong? Wrong code? Wrong placement? Relevant code is nestled within gameLoop. Thanks, regards.
BTW - the lasers are in a table so they can keep their own direction (rotation) and wrap around the screen accordingly.
local function gameLoop() -- Create new asteroid -- wrap lasers around screen for i = #laserTable, 1, -1 do local thisLaser = laserTable[i] if (thisLaser.x \> display.contentWidth + (fudgeNum \* .5)) then thisLaser.x = -(fudgeNum \* .5) else if (thisLaser.x \< -(fudgeNum \* .5)) then thisLaser.x = display.contentWidth + (fudgeNum \* .5) else if (thisLaser.y \< -(fudgeNum \* .5)) then thisLaser.y = display.contentHeight + (fudgeNum \* .5) else if (thisLaser.y \> display.contentHeight + (fudgeNum \* .5)) then thisLaser.y = -(fudgeNum \* .5) end end end end local function removeLaser() display.remove(thisLaser) table.remove(laserTable,i) end timer.performWithDelay ( 1000, removeLaser ) end end