Creating an indefinite amount of physical objects

Hello,

I’m converting a game to Corona, I was wondering how I should create several objects during a certain amount of time, from an image and with physics, currently I’m trying this:

local function spawnShapes()  
 circle = display.newImage( "assets/circle.png", math.random(10), math.random(20) )  
 circle.addBody( puck, {density=1, friction=1, bounce=0.5, rotation=5} )  
end  
  
local clockTimer = timer.performWithDelay( 1000, spawnShapes, -1 )  

but it doesn’t work at all, I mean without physics it does, with physics it doesn’t.

I looked at the fishes example and maybe I should use groups but in the example it shows a fixed amount (10) while I need to spawn objects at fixed interval during the gameplay, they could be 10 they could be thousands.

Thanks.

Since we are here a quick couple of questions to avoid clogging the forums:

  1. Is it possible to resize an image after display.newImage
  2. Is corona going to apply a collision mask automatically or do I have to do it? [import]uid: 118481 topic_id: 21708 reply_id: 321708[/import]

here’s a small snippet that fires a lot of balls of different size, density and bounciness:

local physics = require("physics")  
physics.start()  
physics.setGravity( 0, 40 ) -- it's like... jupiter  
local balls = {} -- table that keeps track of our balls.. uhm...  
local randomBall = function()  
 local ball  
 local ballRad = math.random(10) + 1  
 local ballDens = ballRad/10  
 local ballBounce = (ballRad - 5) / 10  
 ball = display.newCircle( 160, -20, ballRad)  
 ball.x = 160; ball.y = -20  
 physics.addBody( ball, { density=1, friction=0.6, bounce=ballBounce, radius=ballRad } )  
 ball.angularVelocity = math.random(800) - 400  
 balls[#balls + 1] = ball   
end   
timer.performWithDelay( 10, randomBall, -1 )  

hope it helps
-finefin [import]uid: 70635 topic_id: 21708 reply_id: 86147[/import]

I see thanks, so basically I need tables to store the different objects.

If I have to check for a collision what should I use, the table?
Also if I wanted to stop or change the timing of the timer event what would be the best way to do it?

Thanks again! [import]uid: 118481 topic_id: 21708 reply_id: 86221[/import]