Page 1 of 1

How can I make text disappear

Posted: Mon Sep 01, 2008 10:22 pm
by keyspinner
Say, make text saying "level 1" appear then after 3 seconds fade out or disappear and something else load?
Yes I know there is the update function but I need someone to walk me through how to use it because the documentation doesn't really help.

Re: How can I make text disappear

Posted: Mon Sep 01, 2008 11:18 pm
by mike
What do you mean the documentation isn't helpful? Maybe you're not using it right (I know how stupid it is to blame you for this so if you have any tips for the documentation then please lay them on us).
Anyway to make disappear you just have to change the color used to draw it.

Colors come in this simple format:
red, green, blue, alpha
Where each value can go from 0 (no color) to 255 (full color). These are conveniently passed to the function love.graphics.setColor:

Code: Select all

love.graphics.setColor(red, green, blue, alpha)
So, if you want something to disappear, you just slowly decrease the amount of alpha until it's 0 (alpha determines how visible the color is, 255 being fully visible while 0 is invisible).

Here is a demo of it in action:

Code: Select all

function load()
	love.graphics.setFont(love.graphics.newFont(love.default_font, 12)) -- a test font
	alpha = 255
end

function update(dt)
	alpha = alpha - (dt * (255 / 3)) -- so it takes 3 seconds to remove all the alpha
	if alpha < 0 then alpha = 0 end -- to ensure that a 0 is the lowest value we get
end

function draw()
	love.graphics.setColor(255,255,255,alpha) -- this would draw white and then fade out
	love.graphics.draw("text", 100, 100)
end

Re: How can I make text disappear

Posted: Mon Sep 01, 2008 11:25 pm
by keyspinner
Well, the documentation doesn't help because I basically suck at understanding stuff. I need people to explain stuff to me.

Re: How can I make text disappear

Posted: Mon Sep 01, 2008 11:26 pm
by mike
I suck at explaining so we might have a clash here... did you understand what I said, though?

Re: How can I make text disappear

Posted: Mon Sep 01, 2008 11:34 pm
by keyspinner
Surprisingly, in a room full of chatting relatives, I did.
But now my keyreleased that goes to my next .lua doesn't load.
Do you want me to post my code?

Re: How can I make text disappear

Posted: Mon Sep 01, 2008 11:50 pm
by qubodup
keyspinner wrote:Do you want me to post my code?
no.

Also known as "Don't ask to ask and ask."

So basically, yes.

Re: How can I make text disappear

Posted: Mon Sep 01, 2008 11:57 pm
by keyspinner
You confused me, but I think I know what you mean.

main.lua

Code: Select all

function load()
    font = love.graphics.newFont(love.default_font, 12)
    love.graphics.setFont(font)
    title = "lua demo"
    play = "press space to play"
    end

    function draw()
    love.graphics.draw(title, 50, 50)
    love.graphics.draw(play, 400, 300)
    end

    function keyreleased(key)
    if key == love.key_space then
    love.filesystem.require("first.lua")
    load()
    end

    end
	

first.lua

Code: Select all

  function load()
    love.graphics.setFont(love.graphics.newFont(love.default_font, 12))
	alpha = 255
    message = "Level 1"
	player = love.graphics.newImage("player.jpg")
	end
	
    function draw()
	love.graphics.setColor(255,255,255,alpha)
    love.graphics.draw(message, 400, 300)
    end

		function update(dt)
		alpha = alpha - (dt * (255 / 3))
		if alpha > 0 then alpha = 0 end
	end 
Now, I want to be able to make first.lua's text (level 1) fade out and not come back then I want to make the player/level to fade in,
but when I put the fade thing in my first.lua it doesn't work.

Re: How can I make text disappear

Posted: Tue Sep 02, 2008 4:02 am
by Merkoth
I'm pretty sleepy right know, but it would certainly help if you also posted the error LÖVE is throwing back at you. At least a screenshot of that lövely blue screen.

Re: How can I make text disappear

Posted: Tue Sep 02, 2008 2:41 pm
by keyspinner
I would love to post an error, but there is none, the keyreleased function just doesn't work.