Question from a LOVE newbie

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Anooxy
Prole
Posts: 4
Joined: Sat Jul 23, 2011 1:49 am

Question from a LOVE newbie

Post by Anooxy »

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.

Here is my code:

Code: Select all

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

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Question from a LOVE newbie

Post by bartbes »

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.
Anooxy
Prole
Posts: 4
Joined: Sat Jul 23, 2011 1:49 am

Re: Question from a LOVE newbie

Post by Anooxy »

oh silly me.

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'?
User avatar
Trappingnoobs
Citizen
Posts: 95
Joined: Tue Oct 12, 2010 8:52 pm

Re: Question from a LOVE newbie

Post by Trappingnoobs »

Do something like this

Code: Select all

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

Code: Select all

frames_to_wait = .
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Question from a LOVE newbie

Post by bartbes »

No. Don't do that. Seriously, don't. Work based on time, never on frames.
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Question from a LOVE newbie

Post by slime »

Trappingnoobs wrote:Do something like this

Code: Select all

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

Code: Select all

frames_to_wait = .
Don't do this, it will produce different results depending on your framerate, which is bad.

Here's a ridiculously simplified example which is time-based rather than framerate-based.

Code: Select all

ffunction love.load()
	timeleft = 5 -- 5 seconds
end

function love.update(dt)
	timeleft = timeleft - dt
	if timeleft <= 0 then
		-- do stuff here
	end
end
User avatar
Trappingnoobs
Citizen
Posts: 95
Joined: Tue Oct 12, 2010 8:52 pm

Re: Question from a LOVE newbie

Post by Trappingnoobs »

slime wrote:
Trappingnoobs wrote:Do something like this

Code: Select all

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

Code: Select all

frames_to_wait = .
Don't do this, it will produce different results depending on your framerate, which is bad.

Here's a ridiculously simplified example which is time-based rather than framerate-based.

Code: Select all

ffunction love.load()
	timeleft = 5 -- 5 seconds
end

function love.update(dt)
	timeleft = timeleft - dt
	if timeleft <= 0 then
		-- do stuff here
	end
end
Yeah I should've advised using dt. Do Slime's solution; not mine.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Question from a LOVE newbie

Post by GijsB »

or just do this =

d = 0
love.update(dt)
d = d+dt
if d > SECONDS then
--bladiblado stuff
d = 0
end
end
Anooxy
Prole
Posts: 4
Joined: Sat Jul 23, 2011 1:49 am

Re: Question from a LOVE newbie

Post by Anooxy »

slime wrote:
Trappingnoobs wrote:Do something like this

Code: Select all

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

Code: Select all

frames_to_wait = .
Don't do this, it will produce different results depending on your framerate, which is bad.

Here's a ridiculously simplified example which is time-based rather than framerate-based.

Code: Select all

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?
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Question from a LOVE newbie

Post by kraftman »

You could give each thing that you want to fade in its own timer.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 12 guests