Fading Not Working

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
X888X
Prole
Posts: 2
Joined: Sat Jan 24, 2015 8:05 pm

Fading Not Working

Post by X888X »

All I get is a blank screen, I want to have a fade in and fade out thing for my game intro, but it isn't working, please help.

Code: Select all

alpha = 255
seconds = 2

function love.update(delayTime)
	if alpha == 255 then
		alpha = alpha-(255/seconds*delayTime)
	elseif alpha == 0 then
		alpha = alpha+(255/seconds*delayTime)
	end
end

function love.draw()
	if alpha == 255 then
		love.graphics.printf("CodeX Studios Presents...", 0, 250, 800, "center")
		love.graphics.setColor(255, 255, 255, alpha)
		love.graphics.setNewFont(48)
	elseif alpha == 0 then
		love.graphics.reset()
		love.graphics.printf("A Game", 0, 250, 800, "center")
		love.graphics.setColor(255, 255, 255, alpha)
		love.graphics.setNewFont(48)
	end
end
Joe Black
Prole
Posts: 39
Joined: Wed Jan 21, 2015 1:57 pm

Re: Fading Not Working

Post by Joe Black »

the fact is that :
- first loop alpha is decreased
-> so alpha ~= 255 and alpha ~= 0 so nothing is drawn
- second loop alpha ~= 255 and alpha ~= 0 so nothing is changed
-> idem above.

note that in love.draw you do the same whereas somethin or the other

Code: Select all

alpha = 255
seconds = 2

function love.update(delayTime)
        if alpha >= 255 then -- >= is important because you will pass above 255 without passing by 255 itself look at the addition
                decrease=true
        elseif alpha <= 0 then -- idem
                decrease=false
        end
        if decrease then
                alpha = alpha-(255/seconds*delayTime)
        else 
                alpha = alpha+(255/seconds*delayTime)
        end
end

function love.draw()
        love.graphics.printf("CodeX Studios Presents...", 0, 250, 800, "center")
        love.graphics.setColor(255, 255, 255, alpha)
        love.graphics.setNewFont(48)
end
X888X
Prole
Posts: 2
Joined: Sat Jan 24, 2015 8:05 pm

Re: Fading Not Working

Post by X888X »

Joe Black wrote:the fact is that :
- first loop alpha is decreased
-> so alpha ~= 255 and alpha ~= 0 so nothing is drawn
- second loop alpha ~= 255 and alpha ~= 0 so nothing is changed
-> idem above.

note that in love.draw you do the same whereas somethin or the other

Code: Select all

alpha = 255
seconds = 2

function love.update(delayTime)
        if alpha >= 255 then -- >= is important because you will pass above 255 without passing by 255 itself look at the addition
                decrease=true
        elseif alpha <= 0 then -- idem
                decrease=false
        end
        if decrease then
                alpha = alpha-(255/seconds*delayTime)
        else 
                alpha = alpha+(255/seconds*delayTime)
        end
end

function love.draw()
        love.graphics.printf("CodeX Studios Presents...", 0, 250, 800, "center")
        love.graphics.setColor(255, 255, 255, alpha)
        love.graphics.setNewFont(48)
end
Works thanks!!!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], plexity and 2 guests