function fadeGraphicIn(graphic, fadetime, _x, _y, scale)
local fade = fadetime
local alphachange = 255 / fadetime * 0.1
local alpha = 0
while fade > 0 do
love.timer.sleep( 0.1 )
fade = fadetime - 0.1
love.graphics.setColor(255, 255, 255, alpha )
love.graphics.draw(graphic, _x, _y)
alpha = alpha + alphachange
end
end
This function is called by love.draw() as the game starts to fade in a .PNG image that says "Made with LOVE", but the game completely locks up. If anyone knows what I'm doing wrong, I'd really appreciate any help they could offer. Once I've got this function working I'll be able to make the fadeout function easily.
The game locks up because you're telling it to sleep for 0.1s every frame (multiple times, since it's also inside a while loop). love.draw is called every frame, so your function is getting called every frame and your function, on top of sleeping everything, is drawing the image multiple times per frame and doing the whole fading logic in one frame, not along the fadetime. You're also forgetting to use setColorMode so that the current color affects your drawn images.
To get fading (out) working properly I'd do something like this:
function love.load()
fade_time = 5
fade_timer = 5
love.graphics.setColorMode('modulate')
image = love.graphics.newImage()
end
function love.update(dt)
if fade_timer > 0 then fade_timer = fade_timer - dt end
end
function love.draw()
love.graphics.setColor(255, 255, 255, fade_timer*(255/fade_time))
love.graphics.draw(image, )
end
While your example didn't work the way I needed it to, I fixed what you pointed out (I've gotta say I'm a bit embarrassed I didn't realize it from the start, haha!) and got it working (for the most part)! Thanks a billion!