Re: Delay on a loop?
Posted: Wed Mar 05, 2014 2:52 am
Oh... thanks>:D
I tried implementing dt checking into my code, but unfortunately.... it does not do anything now,
It showed the last image before.. now it shows nothing.
This is in tank.lua (I used require"")
space_pressed = false
bullet = love.graphics.newImage("Images/bullet.png")
exp1 = love.graphics.newImage("Images/exp1.png")
exp2 = love.graphics.newImage("Images/exp2.png")
exp3 = love.graphics.newImage("Images/exp3.png")
less = 200
wait = 1
waiter = 1
debounce = true
state = 'nothing'
function love.update(dt)
if state == 'nothing' then
state = 'waiting'
timer = 0.08
end
if state == 'waiting' then
timer = timer - dt
end
if timer <= 0 then
state = 'nothing'
end
end
function attack()
debounce = false
bulletxpos = xpos
bulletypos = ypos
love.graphics.setColor(255,255,255)
if state == 'nothing' then
state = 'waiting'
Bullet = love.graphics.draw(bullet,bulletxpos,bulletypos)
repeat bulletpos = bulletpos - 1 until bulletpos == xpos - less
end
if state == 'nothing' then
state = 'waiting'
EXP1 = love.graphics.draw(exp1,bulletxpos,bulletypos - less)
end
if state == 'nothing' then
state = 'waiting'
EXP2 = love.graphics.draw(exp2,bulletxpos,bulletypos - less)
end
if state == 'nothing' then
state = 'waiting'
EXP3 = love.graphics.draw(exp3,bulletxpos,bulletypos - less)
space_pressed = false
debounce = true
end
end
This is ithe part of main.lua where it does attack function
function love.draw()
if space_pressed == true and debounce == true then
attack()
end
Help please
I tried implementing dt checking into my code, but unfortunately.... it does not do anything now,
It showed the last image before.. now it shows nothing.
This is in tank.lua (I used require"")
space_pressed = false
bullet = love.graphics.newImage("Images/bullet.png")
exp1 = love.graphics.newImage("Images/exp1.png")
exp2 = love.graphics.newImage("Images/exp2.png")
exp3 = love.graphics.newImage("Images/exp3.png")
less = 200
wait = 1
waiter = 1
debounce = true
state = 'nothing'
function love.update(dt)
if state == 'nothing' then
state = 'waiting'
timer = 0.08
end
if state == 'waiting' then
timer = timer - dt
end
if timer <= 0 then
state = 'nothing'
end
end
function attack()
debounce = false
bulletxpos = xpos
bulletypos = ypos
love.graphics.setColor(255,255,255)
if state == 'nothing' then
state = 'waiting'
Bullet = love.graphics.draw(bullet,bulletxpos,bulletypos)
repeat bulletpos = bulletpos - 1 until bulletpos == xpos - less
end
if state == 'nothing' then
state = 'waiting'
EXP1 = love.graphics.draw(exp1,bulletxpos,bulletypos - less)
end
if state == 'nothing' then
state = 'waiting'
EXP2 = love.graphics.draw(exp2,bulletxpos,bulletypos - less)
end
if state == 'nothing' then
state = 'waiting'
EXP3 = love.graphics.draw(exp3,bulletxpos,bulletypos - less)
space_pressed = false
debounce = true
end
end
This is ithe part of main.lua where it does attack function
function love.draw()
if space_pressed == true and debounce == true then
attack()
end
Help please