Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. HashMap... am I doing it wrong?

HashMap... am I doing it wrong?

Scheduled Pinned Locked Moved Java
graphicsdata-structureshelpquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephen Dycus
    wrote on last edited by
    #1

    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.

    S P 2 Replies Last reply
    0
    • S Stephen Dycus

      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.

      S Offline
      S Offline
      Stephen Dycus
      wrote on last edited by
      #2

      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()

      P 1 Reply Last reply
      0
      • S Stephen Dycus

        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.

        P Offline
        P Offline
        Peter_in_2780
        wrote on last edited by
        #3

        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 every put(). Peter

        Software rusts. Simon Stephenson, ca 1994.

        S 1 Reply Last reply
        0
        • S Stephen Dycus

          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()

          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          snap! You got it while I was typing (and taking a phone call....) Cheers, Peter

          Software rusts. Simon Stephenson, ca 1994.

          S 1 Reply Last reply
          0
          • P Peter_in_2780

            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 every put(). Peter

            Software rusts. Simon Stephenson, ca 1994.

            S Offline
            S Offline
            Stephen Dycus
            wrote on last edited by
            #5

            Yup, had just posted that. XD Thank you though ^^

            1 Reply Last reply
            0
            • P Peter_in_2780

              snap! You got it while I was typing (and taking a phone call....) Cheers, Peter

              Software rusts. Simon Stephenson, ca 1994.

              S Offline
              S Offline
              Stephen Dycus
              wrote on last edited by
              #6

              Np, thanks for trying. ^^

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups