Hi everyone.
I’m new to Corona and this is my first post so go easy. I hope someone can help.
I’m trying to make a simple program which generates a cirle just off the top of the screen, and at a random x coordinate, with a random radius.
The circle falls, and when it moves off the bottom of the screen it is killed, or it moves back to the top of the screen. Its x position and radius are again randomly generated and it falls again.
The goal is ultimately to have objects spawn on a timer, but never have more than x amount on screen at once.
Also, I need to know whether it’d be easier to simply make them physics objects with gravity?
My code at the moment looks like this:
____________________________________________________________________
_H = display.contentHeight;
_W = display.contentWidth;
mRand = math.random;
–create local variables
local cratercount = 5
local terrainspeed = 20
local craterx = mRand (0, _W)
local craterrad = mRand (30, 100)
local cratery = _H - _H - craterrad
–create the logic to spawn multiple craters, which is then called by the timer.
local crater = display.newCircle ( craterx,cratery - craterrad,craterrad )
–create the logic to move the crater, which is then called by the timer.
local function moveCrater()
crater.y = crater.y + terrainspeed
–kill the crater once it hits the bottom of the screen
if crater.y > _H + craterrad then
crater.x = mRand (0, _W)
crater.y = _H - _H - craterrad
craterrad = mRand (30, 100)
end
end
–creates a timer which calls the move crater function, so moves by an increment of terrainspeed
–every x milliseconds.
Mcrater = timer.performWithDelay(10, moveCrater, -1);
____________________________________________________________________
Can anyone help or point me in the right direction please?
Thanks
Dan [import]uid: 67933 topic_id: 12297 reply_id: 312297[/import]