Hello, I'm trying to get the map1 bitmap value to be different images depending on what mapnum value is passed to it.
Thank you so much.Code:world_map2::world_map2(int mapnum) { map1=load_bitmap("images/maps/planet1.bmp", NULL); }
This is a discussion on Dynamic BITMAP value within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm trying to get the map1 bitmap value to be different images depending on what mapnum value is passed ...
Hello, I'm trying to get the map1 bitmap value to be different images depending on what mapnum value is passed to it.
Thank you so much.Code:world_map2::world_map2(int mapnum) { map1=load_bitmap("images/maps/planet1.bmp", NULL); }
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.
I'm not sure if that'd work for you or not.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; }
Last edited by Oldman47; 04-15-2007 at 03:39 PM. Reason: added funky example
well, if you need to add bitmaps at runtime, I'd use an std::map.
if not, then just hardcode an arrayCode:std::map<int, std::string> bitmaps; bitmaps[0] = "bmp1"; bitmaps[1] = "bmp2"; world_map2::world_map2(int mapnum) { map1=load_bitmap(bitmaps[mapnum], NULL); }
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?