function love.load()
display = {}
timer = 0
end
function love.draw()
love.graphics.print(timer, 10, 10) -- showing current timer
for i,v in ipairs(display) do
love.graphics.print(v, 10, 10 + i*15)
end
end
function love.update(dt)
timer = timer + 1*dt -- go!
for i=1,5 do
if timer >= i then
table.insert(display, i.." second")
end
end
end
of course it don't work
is there any tutorials about timers and events?
function love.load()
display = {}
timer = 0
times_left = 5
end
function love.draw()
love.graphics.print(timer, 10, 10) -- showing current timer
for i,v in ipairs(display) do
love.graphics.print(v, 10, 10 + i*15)
end
end
function love.update(dt)
if times_left > 0 then
timer = timer + dt
if timer >= 1 then
times_left = times_left - 1
timer = 0
table.insert(display, i.." second")
end
end
end
timers are weird indeed. if i have e.g. 5 simultaneous events on screen than i must have 5 different timer vars on love.load? that's not looks very handy for me.
delta time is a love's thing or lua's?
function menuBattleSpawn()
menuBattle = {
attack = {
name = 'Attack',
entry = {}
}, item = {
name = 'Items',
entry = {}
}, skill = {
name = 'Skill',
entry = {}
}
}
end
function menuBattleDraw()
love.graphics.setFont(big)
for i,v in ipairs(menuBattle) do
for ind,val in ipairs(v) do
love.graphics.print(ind.name, 100, i+200)
end
end
end
You can iterate of all entries (not only the ones with numeric keys) by using "pairs" instead of "ipairs". In that case you have to keep track of the coordinates by hand.
local ent = {
registered = {
apple = love.fileysytem.load( "entities/apple.lua" ) -- Assuming there is a file called "apple.lua" inside a folder called "entities" inside your main directory.
banana = love.filesystem.load( "entities/banana.lua" ) --Remember, this just loads it.
}
} --I do the table this way because it saves a bit of memory.
function ent.new( name )
if not ent.registered[name] then error( "Entity error: did not register "..name.."." ) end
local e = ent.registered[name]()
return e
end
return ent
local ent = require( "entity.lua" )
function love.load()
apple = ent.new( "apple" )
end
That's really the one I use the most. If you want a particular example, just ask!
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim