How do i make text fade to black?

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
Sonic Eclipse
Prole
Posts: 1
Joined: Fri Mar 20, 2020 1:09 pm

How do i make text fade to black?

Post by Sonic Eclipse »

I'm new to love and programming in general so i don't have the expertise that other people may have. I'm trying to make my text fade to black but i don't know how. Help would be greatly appreciated. here's my (probably terrible) code for reference:

Code: Select all

-- Escapism
-- Created by Sonic Eclipse
-- conf.lua



-- Load up required libraries before anything else.
require("assets.libs.TESound-master.tesound")
require("assets.libs.tween-master.tween")



 -- Set up game window.
function love.load()
  love.window.setTitle('Escapism')
  love.window.setMode(800, 600, {fullscreentype=desktop, resizable=true})
  
-- Variables & other stuff
  love.graphics.setNewFont("/fonts/MindEscape.ttf", 55) --The font i'm using.
  local backgroundcolor = {255, 255, 255}
  GameBootTheme = ("/music & sfx/VistaBeta.wav") -- Temporary.
  TEsound.play(GameBootTheme, "static")
end



function love.draw()
  love.graphics.print("C: Hello Human\nH: Hello Computer", 200, 200)
end
Most things here are just placeholders. Also, unrelated question but i tried to make the music i made with Deflemask play but everytime i execute the project it just slaps my screen with "Could not play with ModPlug" or something like that so i had to resort to using a placeholder wave file untill i (or someone that can help) finds a solution to this problem. I thought you could play tracker formats in Love? again, help would be greatly appreciated.

Code: Select all

if not ok then return end
sphyrth
Party member
Posts: 260
Joined: Mon Jul 07, 2014 11:04 am
Contact:

Re: How do i make text fade to black?

Post by sphyrth »

Here's a quick and dirty solution for you to study. Asides from other things, take note that it's fading to black... not making the text invisible.

Code: Select all

function love.load()
  r = 255
  g = 255
  b = 255
end

function love.update(dt)
  r = r - 1
  g = g - 1
  b = b - 1
end

function love.draw()
  love.graphics.setColor(r/255, g/255, b/255)
  love.graphics.print("I'm Fading!")
  love.graphics.setColor(1,1,1) -- Set every other color back to normal
end
User avatar
4vZEROv
Party member
Posts: 126
Joined: Wed Jan 02, 2019 8:44 pm

Re: How do i make text fade to black?

Post by 4vZEROv »

sphyrth wrote: Wed May 06, 2020 1:59 am
Colors are 0-1, not 0-255.

What you want to do, changing a value in a given amount of time, is a very common topic called "tweening".
I recommand you to check "hump.timer", it's a library wich allow you to do timing and tweening stuff easily.

src: https://github.com/vrld/hump/blob/master/timer.lua
doc: https://hump.readthedocs.io/en/latest/t ... -functions
Last edited by 4vZEROv on Wed May 06, 2020 3:08 am, edited 1 time in total.
sphyrth
Party member
Posts: 260
Joined: Mon Jul 07, 2014 11:04 am
Contact:

Re: How do i make text fade to black?

Post by sphyrth »

4vZEROv wrote: Wed May 06, 2020 3:06 am Colors are 0-1, not 0-255.
Yes, that's why I went with this code on love.draw()

Code: Select all

love.graphics.setColor(r/255, g/255, b/255)
CalvinJ
Prole
Posts: 1
Joined: Wed May 13, 2020 8:10 pm

Re: How do i make text fade to black?

Post by CalvinJ »

sphyrth wrote: Wed May 06, 2020 1:59 am Here's a quick and dirty solution for you to study. Asides from other things, take note that it's fading to black... not making the text invisible.
If you want to make it fade out to invisible perchance, you can just reduce the alpha value like so. That way if your background is colored, black text won't stand out.

Code: Select all

function love.load()
  r = 255
  g = 255
  b = 255
  a = 255
end

function love.update(dt)
  a = a - 1
end

function love.draw()
  love.graphics.setColor(r/255, g/255, b/255, a/255)
  love.graphics.print("I'm Fading!")
  love.graphics.setColor(1,1,1) -- Set every other color back to normal
end
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How do i make text fade to black?

Post by zorg »

Also, regarding the music thing,

Löve uses libmodplug to play back specific, sample(r)-based tracker formats; it has a neat list what it supports, but here are the list of things it doesn't:
- Any deflemask format, because those aren't sample-based, they are sound-chip based;
- FamiTracker, for the same reason, uses the chip found in the NES;
- HivelyTracker, because it simulates a SID chip;
- Klystracker, same as above;
- Abyss' Highest Experience, same as above.
And loads of other tracker formats aren't supported either because they'd be out of scope for libmodplug... as well as the fact that libmodplug's not being actively maintained either (and replacing it with libopenmpt would be complicated to do, but i digress)

You have three options basically,in order of simplicity:
- Render music into wav/ogg/mp3/flac depending on how much of an audiophile you are :3, downside is of course storage space increase;
- Re-compose music in sample-based formats; MOD/S3M/XM/IT are the "big 4" that are most supported; i'd recommend either S3M or IT though, they have the least badly-defined behaviour (and although S3M does support AdLib OPL2 synth channels, libmodplug unfortunately doesn't implement those),
- Implement a replayer for Deflemask formats (whether getting a c lib or doing it in lua). I did the latter for S3M myself as an experiment, and löve handles it nicely, but chip-based is always way over-complicated to implement in software... you can take a peek at how Reality AdLib Tracker 2 implemented an OPL3 chip, since they FOSS-ed the code for it.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

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