Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have two images of the same dimensions. One is represents the game board in a user-appealing way, the other represents it in a computer-friendly way where each game area is painted in a unique, uniform color. When the user clicks the board, we get the click coordinates, find the color of the pixel at the same coordinates in our second image, and that color is directly translatable to a game area, since each area is painted in its own color.

Is that a good implementation? Can you suggest better, if it isn't?

Best regards.

share|improve this question
    
Lacking further context or an actual problem to solve, I'd say "sounds great, go for it" –  Hackworth Apr 14 '12 at 19:28
    
The problem to solve is maybe not stated in a very straightforward way in my post, I still hoped it was apparent. In a short way, what is a (the best?) way to know which area of a map was clicked from screen coordinates? Best regards. –  pouzzler Apr 14 '12 at 20:00

1 Answer 1

up vote 0 down vote accepted

Better to skip the image and just have a 2D array of pointers which indicate what game area it is. Since the second image is never displayed there's no reason for it to contain visible colours.

share|improve this answer
3  
"Colors" is just a method to visualize the concept of a collection of identifiers. There is no difference between an array of int pointers and an array of int colors. The advantage of not using pointers is that you can choose a smaller data structure than int. If you have less than 256 areas, a byte will suffice, whereas a pointer is always an int. –  Hackworth Apr 14 '12 at 22:23
    
A pointer is not always an int. The size of a pointer depends on your platform and whatever your compiler wants it to be (usually you, the user, decide this by targeting x86 or x64). Usually it will be 32 bit (which most of the time matches the size of an int) in 32 bit applications, and 64 bit in 64 bit applications. +1 on that comment though. –  TravisG Apr 14 '12 at 22:44
    
You could just use an enum instead if you want. But my point stands- there's no reason to use a visible colour when it'll never be visible. –  DeadMG Apr 15 '12 at 11:25
    
@DeadMG There seems to be a misunderstanding - The color map the OP proposes is not meant to be rendered, it's only for internally keeping track of areas, just like a pointer would. "Color" in this context is nothing but a mental help to understand the idea of an underlying data structure that the computer understands more easily than a nice map for humans. There are no actual colors being rendered to screen. –  Hackworth Apr 15 '12 at 13:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.