I'm trying to learn LOVE while making a game and the first thing I'm trying to do is make a logo fade in/out then show the menu bg (another image) without buttons (for now).
I tried to get the first image to fade in but it's not fading out for some reason.
function love.load()
-- Set Variables
game_name = "Gaia"
version = "Revision 1"
menu_bg = "UI/main-menu.jpg"
alpha = 0
gstime = love.timer.getTime()
-- Set Window Caption
love.graphics.setCaption(game_name.." "..version)
-- Main Menu
menu_bg = love.graphics.newImage(menu_bg)
end
function love.draw()
love.graphics.setColor(255, 255, 255, alpha)
love.graphics.draw(menu_bg)
end
function love.update(dt)
-- Logo Fade in/out
etime = love.timer.getTime()
if etime-gstime > 0.1 then alpha = alpha + (dt * (255 / 2)) end
if alpha > 255 then alpha = 255 end
if etime-gstime > 5 then alpha = alpha - (dt * (255 / 2)) end
if alpha < 0 then alpha = 0 end
end
Because it keeps fading in (the condition, time being bigger than 0.1 is true even during fadeout), and because they fade in and out at the same rate, there's a net difference of 0.
Also, another newbie question. I have to manage when stuff happens like for e.g. showing the next image with time? Is there no other way to do it like 'when this ends, do this'?
function love.load()
frames_to_wait = 0
end
function love.draw()
if frames_to_wait ~= 0 then
frames_to_wait = frames_to_wait - 1
return
else
--Draw stuff
end
end
Then, in your love.update logic, when you want to stop drawing stuff for x frames, just type
function love.load()
frames_to_wait = 0
end
function love.draw()
if frames_to_wait ~= 0 then
frames_to_wait = frames_to_wait - 1
return
else
--Draw stuff
end
end
Then, in your love.update logic, when you want to stop drawing stuff for x frames, just type
function love.load()
frames_to_wait = 0
end
function love.draw()
if frames_to_wait ~= 0 then
frames_to_wait = frames_to_wait - 1
return
else
--Draw stuff
end
end
Then, in your love.update logic, when you want to stop drawing stuff for x frames, just type
function love.load()
frames_to_wait = 0
end
function love.draw()
if frames_to_wait ~= 0 then
frames_to_wait = frames_to_wait - 1
return
else
--Draw stuff
end
end
Then, in your love.update logic, when you want to stop drawing stuff for x frames, just type
ffunction love.load()
timeleft = 5 -- 5 seconds
end
function love.update(dt)
timeleft = timeleft - dt
if timeleft <= 0 then
-- do stuff here
end
end
What if I need to add another image fadein/out how would I go with the time. I can't possibly do it the same way because the time for the 2nd image needs to be reduced only after the time of the first has ended. I could go the rough way for e.g. if the time of the first image ended then start reducing the time for the 2nd image but is this really a good way to do it?