Fading error
Posted: Thu May 08, 2014 9:02 pm
Hello, I'm not so familiar with Löve and I'm not sure what I'm doing wrong here..
I'll explain what's wrong, when I try fading an image it fades as it should, but for example when it's completly faded out it reappears for about a millisecond or something and then disappears, it's the same when fading it in but it disappears instead and then reappears..
Here's the code I'm using
Note: My indenting of the code may get screwed up when pasting it here
I'll explain what's wrong, when I try fading an image it fades as it should, but for example when it's completly faded out it reappears for about a millisecond or something and then disappears, it's the same when fading it in but it disappears instead and then reappears..
Here's the code I'm using
Code: Select all
function love.load()
--# Fading variables
fade = false;
fade_mode = nil;
fade_time = 5
fade_timer = 5
--# Load test image
image = love.graphics.newImage("logo.png")
end
function love.update(dt)
--# Handle fading
if fade then
--# Fade out
if fade_mode == "out" then
if fade_timer > 0 then
fade_timer = fade_timer - dt
else
if fade_timer < 0 then
fade_timer = 0
end
fade = false;
end
else
--# Fade in
if fade_timer < fade_time then
fade_timer = fade_timer + dt
else
if fade_timer > fade_time then
fade_timer = fade_time
end
fade = false;
end
end
end
end
function fadeOut( rate )
fade = true;
fade_mode = "out";
fade_timer = rate;
fade_time = rate;
end
function fadeIn( rate )
fade = true;
fade_mode = "in";
fade_time = rate;
end
function love.draw()
love.graphics.setColor(255, 255, 255, fade_timer*(255/fade_time))
love.graphics.draw(image, 100, 100)
end
function love.keypressed(key, unicode)
if key == "left" then
if fade_mode == "out" then
fadeIn(2)
else
fadeOut(2)
end
end
end