HashMap... am I doing it wrong?
-
I'm rolling my own text system, or trying to anyways... I cycle through the bitmap to determine the texture coordinates of every character. Then add them to the map via their associated char. Later I cycle through a string to pull the texture coords and add them to the buffer... the coords are correct going in but not pulling out.
private HashMap glyphs = new HashMap();
//cycle bla bla
glyphs.put(c[i], temp);/// later
float temp[] = glyphs.get(a);The array returned is the same one for every char sent to the retrieval function. I must be doing this wrong... any help? EDIT: The coord to be retrieved is the coord of the last thing put into the map.
-
I'm rolling my own text system, or trying to anyways... I cycle through the bitmap to determine the texture coordinates of every character. Then add them to the map via their associated char. Later I cycle through a string to pull the texture coords and add them to the buffer... the coords are correct going in but not pulling out.
private HashMap glyphs = new HashMap();
//cycle bla bla
glyphs.put(c[i], temp);/// later
float temp[] = glyphs.get(a);The array returned is the same one for every char sent to the retrieval function. I must be doing this wrong... any help? EDIT: The coord to be retrieved is the coord of the last thing put into the map.
Figured it out... <.> I wasn't instantiating a new temp each pass. So the last element is stored for every key. Easy fix, just re-instantiate the variable before setting a value and calling put()
-
I'm rolling my own text system, or trying to anyways... I cycle through the bitmap to determine the texture coordinates of every character. Then add them to the map via their associated char. Later I cycle through a string to pull the texture coords and add them to the buffer... the coords are correct going in but not pulling out.
private HashMap glyphs = new HashMap();
//cycle bla bla
glyphs.put(c[i], temp);/// later
float temp[] = glyphs.get(a);The array returned is the same one for every char sent to the retrieval function. I must be doing this wrong... any help? EDIT: The coord to be retrieved is the coord of the last thing put into the map.
I can't see the rest of your code, but it smells like you are reusing the same
temp
, effectively overwriting the same item on everyput()
. PeterSoftware rusts. Simon Stephenson, ca 1994.
-
Figured it out... <.> I wasn't instantiating a new temp each pass. So the last element is stored for every key. Easy fix, just re-instantiate the variable before setting a value and calling put()
snap! You got it while I was typing (and taking a phone call....) Cheers, Peter
Software rusts. Simon Stephenson, ca 1994.
-
I can't see the rest of your code, but it smells like you are reusing the same
temp
, effectively overwriting the same item on everyput()
. PeterSoftware rusts. Simon Stephenson, ca 1994.
Yup, had just posted that. XD Thank you though ^^
-
snap! You got it while I was typing (and taking a phone call....) Cheers, Peter
Software rusts. Simon Stephenson, ca 1994.
Np, thanks for trying. ^^