Thread: Dynamic BITMAP value

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    1

    Dynamic BITMAP value

    Hello, I'm trying to get the map1 bitmap value to be different images depending on what mapnum value is passed to it.
    Code:
    world_map2::world_map2(int mapnum)
    {                                    
          map1=load_bitmap("images/maps/planet1.bmp", NULL);          
    }
    Thank you so much.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Wouldn't you need some type of arguments to do this?

    if mapnum ==1 load this // if mapnum==2 load that.

    Or, perhaps something funky and make your mapnum a string rather than an int. Doesn't matter what the character contained within the string is.

    Code:
    #include <iostream>
    #include <string>
    
    std::string get_number;
    
        void funky(std::string number)
         {
            std::string test="images/maps/planet";
            
            test.append(number);
            test.append(".bmp");
            
            std::cout<<test;
         }
    
    int main ()
    {
      std::cout<<" enter a number: ";
      std::cin>>get_number;
      
    	  funky(get_number);
    	  
      std::cin.ignore();
      std::cin.get();
      
    	return 0;
    }
    I'm not sure if that'd work for you or not.
    Last edited by Oldman47; 04-15-2007 at 03:39 PM. Reason: added funky example

  3. #3
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    well, if you need to add bitmaps at runtime, I'd use an std::map.
    Code:
    std::map<int, std::string> bitmaps;
    
    bitmaps[0] = "bmp1";
    bitmaps[1] = "bmp2";
    
    world_map2::world_map2(int mapnum)
    {                                    
          map1=load_bitmap(bitmaps[mapnum], NULL);          
    }
    if not, then just hardcode an array
    Code:
    static const char* bitmaps[] =
    {
    "images/maps/planet1.bmp",
    "images/maps/planetoftheapes.bmp",
    "images/maps/hoth.bmp",
    "images/maps/magarathea.bmp",
    "images/maps/uranus.bmp" // heh heh
    };
    
    world_map2::world_map2(int mapnum)
    {                                    
          map1=load_bitmap(bitmaps[mapnum], NULL);          
    }
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading a bitmap (Without using glaux)
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 03-16-2006, 09:43 AM
  2. Dynamic Bitmap Display
    By Jaken Veina in forum Windows Programming
    Replies: 5
    Last Post: 07-04-2005, 10:57 AM
  3. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  4. Loading a Bitmap resource for OpenGL Texture[x]
    By the dead tree in forum Game Programming
    Replies: 4
    Last Post: 08-26-2004, 01:12 PM
  5. bitmap not going onto screen
    By stallion in forum Windows Programming
    Replies: 4
    Last Post: 02-22-2003, 10:07 AM