Hello, so, my game has a very bright background image, and I basically want the love.graphics.rectangles that I'm doing to be black without making the screen go completely black.
When I set those same rectangles to red, for eg, everything in the screen turns reddish. In my old pong game, I used a dark background image, and somehow I didn't need to use a love.graphics.clear() to clear the graphics / canvas. In these one I needed to use that.
So, is there an easy way to set the colors without influencing the entire background image?
Bright background image and black graphics
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- galoctopus
- Prole
- Posts: 6
- Joined: Sat Oct 17, 2015 1:58 pm
-
- Party member
- Posts: 732
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Bright background image and black graphics
Well set the color every time you want it different. Basically what I mean is make sure you draw the image with the color you desire. Which in most cases is white.
Code: Select all
lg.setColor(255,255,255)
--draw image
lg.setColor(0,0,0)
--rect
lg.setColor(255,0,0)
--draw fps counter
lg.setColor(0,255,0)
--draw your reaction to a simple solution (hopefully it's the solution)
- galoctopus
- Prole
- Posts: 6
- Joined: Sat Oct 17, 2015 1:58 pm
Re: Bright background image and black graphics
I still do have a black screen 
This is my code:
And inside aspectRatio() I have this:

This is my code:
Code: Select all
love.graphics.setCanvas(canvas)
love.graphics.clear()
love.graphics.setColor(255,255,255)
love.graphics.draw(galoctopus, 0, 0)
love.graphics.setColor(0,0,0)
love.graphics.rectangle('fill', paddle1X, paddle1Y, paddle1W, paddle1H)
love.graphics.rectangle('fill', paddle2X, paddle2Y, paddle2W, paddle2H)
love.graphics.rectangle('fill', ballX, ballY, ballW, ballH)
love.graphics.rectangle('fill', canvasW/2 - 1, 0, 2, canvasH)
love.graphics.setCanvas()
aspectRatio()
Code: Select all
function aspectRatio()
getScreenW, getScreenH = love.graphics.getDimensions()
getCanvasW, getCanvasH = canvas:getDimensions()
scale = math.min(getScreenW/getCanvasW, getScreenH/getCanvasH)
centerCanvasW = math.floor((getScreenW - getCanvasW*scale)/2)
centerCanvasH = math.floor((getScreenH - getCanvasH*scale)/2)
canvas:setFilter('nearest', 'nearest')
love.graphics.push()
love.graphics.translate(centerCanvasW, centerCanvasH)
love.graphics.scale(scale, scale)
love.graphics.draw(canvas)
love.graphics.pop()
end
-
- Party member
- Posts: 732
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Bright background image and black graphics
Um just a small suggestion, you should use local variables in your functions. For example getScreenW could be a local. Do you set the color and blendmode properly when drawing the canvas?
Are you doing
Or
Are you doing
Code: Select all
setColor(255,255,255)
--draw canvas
Code: Select all
--draw canvas
Re: Bright background image and black graphics
The canvas is an "image" of sorts too and you're not setting the color to 255,255,255 before drawing it so the colors are all screwed up.
s-ol.nu
Code: Select all
print( type(love) )
if false then
baby:hurt(me)
end
- zorg
- Party member
- Posts: 3478
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Bright background image and black graphics
The technical term for the type löve uses for both canvases and images is Texture.
And as S0lll0s said, you want to do love.graphics.setColor(255,255,255,255) before drawing the canvas itself, or, depending on blendmode, color and/or the active shader, it might result in something you don't want.
And as S0lll0s said, you want to do love.graphics.setColor(255,255,255,255) before drawing the canvas itself, or, depending on blendmode, color and/or the active shader, it might result in something you don't want.
Me and my stuff
True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

-
- Party member
- Posts: 732
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Bright background image and black graphics
Guys yall literally repeated what I said twice lol.
Re: Bright background image and black graphics
sort of, but yours was phrased as a question that was already answered by his small code dump. I pointed out what he had to do to fix itbobbyjones wrote:Guys yall literally repeated what I said twice lol.

s-ol.nu
Code: Select all
print( type(love) )
if false then
baby:hurt(me)
end
Who is online
Users browsing this forum: Ahrefs [Bot] and 4 guests