Bright background image and black graphics

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
galoctopus
Prole
Posts: 6
Joined: Sat Oct 17, 2015 1:58 pm

Bright background image and black graphics

Post by galoctopus »

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?
bobbyjones
Party member
Posts: 732
Joined: Sat Apr 26, 2014 7:46 pm

Re: Bright background image and black graphics

Post by bobbyjones »

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)
User avatar
galoctopus
Prole
Posts: 6
Joined: Sat Oct 17, 2015 1:58 pm

Re: Bright background image and black graphics

Post by galoctopus »

I still do have a black screen :(
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()
And inside aspectRatio() I have this:

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
bobbyjones
Party member
Posts: 732
Joined: Sat Apr 26, 2014 7:46 pm

Re: Bright background image and black graphics

Post by bobbyjones »

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

Code: Select all

setColor(255,255,255)
--draw canvas
Or

Code: Select all

--draw canvas
User avatar
s-ol
Party member
Posts: 1080
Joined: Mon Sep 15, 2014 7:41 pm
Location: Milan, Italy
Contact:

Re: Bright background image and black graphics

Post by s-ol »

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
User avatar
zorg
Party member
Posts: 3478
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Bright background image and black graphics

Post by zorg »

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.
Me and my stuff :3True 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.
bobbyjones
Party member
Posts: 732
Joined: Sat Apr 26, 2014 7:46 pm

Re: Bright background image and black graphics

Post by bobbyjones »

Guys yall literally repeated what I said twice lol.
User avatar
s-ol
Party member
Posts: 1080
Joined: Mon Sep 15, 2014 7:41 pm
Location: Milan, Italy
Contact:

Re: Bright background image and black graphics

Post by s-ol »

bobbyjones wrote:Guys yall literally repeated what I said twice lol.
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 it :P

s-ol.nu

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests