Sprite maps

Hi everyone, I’m new to the website and I just have a quick question. I’ve made a sprite sheet for the text for a 2D game I’m currently trying to give legs. Here’s the image: http://i.imgur.com/eLIhJ.png
It’s very basic. Each character on the sheet is 20x20 pixels and what I need is a sort of mechanism to map out the x and y coordinate for the top left hand corner of each character. The way I’ve structured the rest of the classes involved, I have a text string that I loop through each character of, which determines the square of the image that is rendered. I’ve considered just making a separate class with 3 fields, namely: character, xPos and yPos. Then for each character in the string that I’m trying to render I loop through the characters and check whether there’s a match, then return the xPos and yPos, however I would imagine this to be quite an inefficient solution. Does anyone know a good method for mapping data?

Thanks in advance,

Paul

Use a Map<Char,Position> where Position is a class containing xPos and yPos. You can do it with a HashMap, or you can write your own .get(Char) method that figures out the location on the fly. Then for each character in the string, look it up in the map.

Ah, that’s sounds like what I need. Cheers, I’ll do some reading up.