So, I'm new here and I started off with Loeves Framework by making a "Presentation"-like intro for my (future) game.
The code should do following:
1. Draw a black rectangle over the whole window.
2. Fade the rectangle with the (r, g, b, a) -Value
3.Don't draw the rectangle if the a-Value == 0
My main.lua file is just a skeleton, it serves as modular structure.
The problem is, all other Text (The FPS-Counter), Pictures etc. which are behind this particular black rectangle are being faded too and don't regain their original a-Value when the rectangle isn't being drawn anymore. So, maybe you guys know how to fix the Alpha-Issue there?
Thanks in advance.
main.lua:
Code: Select all
require 'routines.lua'
require 'variables.lua'
function love.load()
extload()
end
function love.update(dt)
extupdate(dt)
end
function love.draw()
extdraw()
end
Code: Select all
function extload()
--load images
image = love.graphics.newImage("1.jpg")
-- set Caption
love.graphics.setCaption("Hi there! Test!")
--set Background Color
love.graphics.setBackgroundColor(255,0,0)
-//init alpha ch
alphach = 255;
-//set picture coordinates
x = 20
y = 30
--//layeractive bool
layeractive = true
--//alpha decrease speed
decrease = 50
--//get length and width of window
maxx = love.graphics.getWidth()
maxy = love.graphics.getHeight()
end
--======================[UPDATE AND DRAW-FUNCTIONS]======================================================
function layershades(dt)
alphach = alphach - (decrease * dt)
if alphach <= 0 then
layeractive = false end
end
function extdraw()
-- draws text
if layeractive == true then
drawlayer()
end
fps = love.timer.getFPS( )
love.graphics.print(fps, 400, 300)
love.graphics.draw(image, x, y)
end
function extupdate(dt)
if layeractive == true then
layershades(dt)
else
end
end
function drawlayer()
love.graphics.setColor(0, 0, 0, alphach)
love.graphics.rectangle("fill", 0, 0, maxx, maxy)
end