• Post Reply Bookmark Topic Watch Topic
  • New Topic

Colour issue (only shows grey)

 
Edmond Corrola
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program generates an 8 by 8 chessboard with alternating black and white squares. I also want to label the white squares with numbers. Here's what I have, I had it working but slightly modified it some time ago and forgot what I changed because now there aren't numbers for the last row and the squares are all grey. Any help would be appreciated, thanks!
[ October 01, 2008: Message edited by: Edmond Corrola ]
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Edmond Corrola:
My program generates an 8 by 8 chessboard with alternating black and white squares. I also want to label the white squares with numbers. Here's what I have, I had it working but slightly modified it some time ago and forgot what I changed because now there aren't numbers for the last row and the squares are all grey.


I'm guessing the squares are grey because you are calling
drawRect() instead of fillRect().

I'm not surprised there aren't numbers in the last row
because you're using y - (size/2) for the y coordinate
instead of y + (size/2). Also, you're starting the counter
at -3 for some reason, which seems odd.

[edit: drawRect() draws the four sides, but doesn't fill the interior.]
[ September 30, 2008: Message edited by: Brian Cole ]
 
Edmond Corrola
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah i see, haha thanks. Didn't even notice the fillRect issue. The "y-size/2" issue for draw string though is if I don't do that, the string gets drawn upwards (into the black regions) and not downwards (into the white regions). What would be a suitable re-write for it?
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Edmond Corrola:
The "y-size/2" issue for draw string though is if I don't do that, the string gets drawn upwards (into the black regions) and not downwards (into the white regions). What would be a suitable re-write for it?


Well it's your code, so do as you wish. But it seems to me that,
since you are iterating through each square with nested loops,
it makes sense to draw text into the current square instead of
the one above. If you're having parity issues you can always
change row%2 == column%2 to row%2 != column%2.
 
Edmond Corrola
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No matter which way I do it i'm missing numbers. Either i'm missing the entire last column, or i'm missing the entire bottom row. If you have a suggestion i'm glad to hear it, because i've tried everything.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!