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);
}
Printable View
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;
}
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);
}