Page 4 of 4

Re: Newbie Color Question

Posted: Tue Feb 08, 2011 8:22 pm
by Robin
chris-kun wrote:huh? the same screenshot I posted? when I open it up in gimp I get the right paddle as #566478 and the left as #7995bf
Oh, right.

I think I know what this is. I had something similar for LovelyBigPlanet, only vertical instead of horizontal. I think it is a bad graphics card or driver or something. It isn't the fault of your code.

Re: Newbie Color Question

Posted: Tue Feb 08, 2011 8:26 pm
by tentus
Y'know, the more I play around with what code has been posted... are we sure the paddles are both getting drawn the same way? It looks like paddle 2 is a line, but paddle 1 is an image. If that's the case, then its little wonder we have color issues. A blue image getting tinted blue would just become a darker blue, like, say, #566478.

Re: Newbie Color Question

Posted: Tue Feb 08, 2011 9:34 pm
by chris-kun
the following code should work:

Code: Select all

function love.load()
   paddlei = love.graphics.newImage('images/paddle.png')
   love.graphics.setMode(850, 650, false, true, 0)
   love.graphics.setColorMode("replace")
   love.graphics.setBackgroundColor(51,51,51)
   p1,p2=0,0 x,bx=850,425 y,by=650,325
   paddle={{x1=25,x2=25,y1=y/2-46,y2=y/2+46,s=0},{x1=825,x2=825,y1=y/2-46,y2=y/2+46,s=0}}
   pc={122, 150, 191}
end

function love.draw()
   love.graphics.setColor(255,255,255)                                       
   love.graphics.setColor(pc)
   love.graphics.line(paddle[2].x1, paddle[2].y1, paddle[2].x2, paddle[2].y2)
   love.graphics.setColor(255,255,255)
   love.graphics.draw(paddlei, paddle[1].x1, paddle[1].y1)
   love.graphics.print(p1,5,5) love.graphics.print(p2,x-13,5)
   love.graphics.setColor(255,255,255)
end
if you need the paddle image:
paddle.png
paddle.png (159 Bytes) Viewed 2286 times

Re: Newbie Color Question

Posted: Tue Feb 08, 2011 9:53 pm
by vrld
You need to add an offset of 0.5 to the line (as well as rectangle) drawing-code to un-blur it:

Code: Select all

love.graphics.line(paddle[2].x1+.5, paddle[2].y1+.5, paddle[2].x2+.5, paddle[2].y2+.5)

Re: Newbie Color Question

Posted: Tue Feb 08, 2011 9:57 pm
by chris-kun
thanks!

Re: Newbie Color Question

Posted: Tue Feb 08, 2011 10:11 pm
by tentus
chris-kun wrote:the following code should work:
Ok, I was right, the problem with the different colors is because one was a line, and the other was an image. Check out the below code (unneeded code removed for clarity):

Code: Select all

function love.load()
	x = 850
	y = 650
	love.graphics.setMode(x, y, false, true, 0)
	love.graphics.setBackgroundColor(51,51,51)
	p1,p2 = 0,0
	paddle={
		{x1=25, x2=25, y1=y/2-46, y2=y/2+46},
		{x1=825, x2=825, y1=y/2-46, y2=y/2+46}
	}
	paddle_color = {122, 150, 191}
	love.graphics.setLineWidth(2)
end

function love.draw()
	love.graphics.setColor(paddle_color)
	for i=1, #paddle do
		love.graphics.line(paddle[i].x1, paddle[i].y1, paddle[i].x2, paddle[i].y2)
	end
	love.graphics.setColor(255,255,255)
	love.graphics.print(p1,5,5)
	love.graphics.print(p2,x-13,5)
end
This will draw both paddles using lines (no image needed) at the same color, which is #7a96bf according to Photoshop: exactly what we told it to be. The only other big difference in this code is that at load I tell the lines to be 2 pixels wide, rather than 1. As vrld pointed out, half-pixels are your enemy: in this case, it's make your line appear to be 2px wide, but also semitransparent, netting you a very dark #525e70-ish color.

Some other friendly advice: use longer variable names, ones that are more descriptive. I assume p1 and p2 represent player scores, but it's not very clear. Same with your x and y variables: they seem to represent the screen width and height, but that has a high chance of tripping you up later.

Another thing you may want to do is change your print statements to printf statements, and then make the right one right-aligned, like so:

Code: Select all

love.graphics.printf(p2, x-55, 5, 50, "right")
I know it looks more complex, but it'll save you from the headache of the player score going offscreen (change p2 to 20 to see what I mean)