i am trying to spawn multiple blocks the it just keeps ressetting rather than spawning another
so when i try to run it it just spawns 1 block and keeps resetting itself.
i am a beginner at coding and i am trying to learn love2d,
thankyou very much for helping
Code: Select all
spawnTimer = 0
-- add
local blocks = {}
function addBlock(x,y,w,h)
block = {x=x,y=y,w=w,h=h}
blocks[#blocks+1] = block
table.insert(blocks,block)
end
function blockUpdate(dt)
-- block spawn timer && spawn
spawnTimer = spawnTimer + 0.01
if spawnTimer > 2 then
local x = love.graphics.getWidth() /2
local y = love.graphics.getHeight() /2
local w = 50
local h = 50
addBlock(x,y,w,h)
print("succes")
spawnTimer = 0
end
-- block scroll
for i=1,#blocks do
local b = block
b.x = b.x - 1
print("-5")
end
end
function blockDraw()
for i=1,#blocks do
local b = block
love.graphics.rectangle("fill",b.x,b.y,b.w,b.h)
end
end