Page 1 of 1

Fading Not Working

Posted: Sat Jan 24, 2015 8:45 pm
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

Re: Fading Not Working

Posted: Sat Jan 24, 2015 9:31 pm
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

Re: Fading Not Working

Posted: Sat Jan 24, 2015 10:01 pm
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!!!