I am working on a function to shoot multiple bullets here it is:
local function shootBullets ( event )
local bullet = display.newImageRect("images/Bullet.png", 12, 12) --Create the bullet image
physics.addBody(bullet, "kinematic", {bounce = 0}) --Allow physics stuff to work on it
bullets:insert( bullet ) --Add it to a global group called "bullets"
bullet:setLinearVelocity(20, 40) --Give it a velocity
end
And I am calling it with this timer:
timer.performWithDelay(10, shootBullets)
It moves one bullet, but it isn’t making new ones. How can I have it spawn new bullets each time I call the shootBullets ( event )? I am not that familiar with Lua so sorry if I am doing something obviously wrong, or if I am not giving enough information (if you need more information, ask).
Oops, I should pay closer attention to the API:
The default 3 parameter for
timer.performWithDelay(time, function, times)is 1. To make it repeat forever I need to make it 0. So I changed:To this:
Now there are bullets.