How can I make text disappear

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.
Post Reply
User avatar
keyspinner
Prole
Posts: 24
Joined: Mon Sep 01, 2008 12:03 am

How can I make text disappear

Post 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.
User avatar
mike
Administrator
Posts: 364
Joined: Mon Feb 04, 2008 5:24 pm

Re: How can I make text disappear

Post 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
Now posting IN STEREO (where available)
User avatar
keyspinner
Prole
Posts: 24
Joined: Mon Sep 01, 2008 12:03 am

Re: How can I make text disappear

Post by keyspinner »

Well, the documentation doesn't help because I basically suck at understanding stuff. I need people to explain stuff to me.
User avatar
mike
Administrator
Posts: 364
Joined: Mon Feb 04, 2008 5:24 pm

Re: How can I make text disappear

Post by mike »

I suck at explaining so we might have a clash here... did you understand what I said, though?
Now posting IN STEREO (where available)
User avatar
keyspinner
Prole
Posts: 24
Joined: Mon Sep 01, 2008 12:03 am

Re: How can I make text disappear

Post 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?
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: How can I make text disappear

Post 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.
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
keyspinner
Prole
Posts: 24
Joined: Mon Sep 01, 2008 12:03 am

Re: How can I make text disappear

Post 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.
User avatar
Merkoth
Party member
Posts: 186
Joined: Mon Feb 04, 2008 11:43 pm
Location: Buenos Aires, Argentina

Re: How can I make text disappear

Post 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.
User avatar
keyspinner
Prole
Posts: 24
Joined: Mon Sep 01, 2008 12:03 am

Re: How can I make text disappear

Post by keyspinner »

I would love to post an error, but there is none, the keyreleased function just doesn't work.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 57 guests