Maybe something like this?
A table to store the arrows.
Creating a local arrow table, and then inserting it into the table of arrows.
Code: Select all
function create_arrow(x, y)
local arrow = {}
arrow.body = love.physics.newBody( World, x, y, "dynamic")
arrow.shape = love.physics.newRectangleShape( 10, 3 )
arrow.fixture = love.physics.newFixture( arrow.body , arrow.shape, 1 )
arrow.fixture:setUserData("Arrow")
table.insert(arrows, arrow)
end
And looping over all of the arrows to check if they're offscreen, and if they are, removing them from the table. (Note that this for loop uses
pairs, not
ipairs.)
Code: Select all
function remove_offscreen_arrows()
for key, arrow in pairs(arrows) do
if is_offscreen(arrow) then
arrows[key] = nil
end
end
end
And calling them.
Code: Select all
function love.update(dt)
remove_offscreen_arrows()
end
function love.mousepressed(x, y)
create_arrow(x, y)
end
I hope this helps!