Skip to main content
deleted 1 characters in body
Source Link
Laurent Couvidou
  • 9.2k
  • 2
  • 42
  • 58

Make sure mymap is really a 2-dimensions array of size MAPWIDTH * MAPHEIGHT. E.g. if that's a plain old array of SDL_Surface pointers, it'sits declaration should be as follows:

SDL_Surface* mymap[MAPWIDTH][MAPHEIGHT];

Then all the images stored in this array have to be loaded in memory before you call this code. That could be a simple loop, assuming you use SDL_image:

for (int x=0; x<MAPWIDTH; ++x)
{
    for (int y=0; y<MAPHEIGHT; ++y)
    {
        mymap[x][y] = IMG_Load( some_function_that_gives_an_image_path(x, y) );
        assert(mymap[x][y]); // to spot if loading fails
    }
}

It's very likely that you'll want to share images between different tiles, so make sure you don't mess up and that every pointer in mymappoints to something real. A debugger might help spotting issues.

Last thing, if you're using some kind of asynchronous loading, you'll have to wait for your images to load before you start rendering them.

Make sure mymap is really a 2-dimensions array of size MAPWIDTH * MAPHEIGHT. E.g. if that's a plain old array of SDL_Surface pointers, it's declaration should be as follows:

SDL_Surface* mymap[MAPWIDTH][MAPHEIGHT];

Then all the images stored in this array have to be loaded in memory before you call this code. That could be a simple loop, assuming you use SDL_image:

for (int x=0; x<MAPWIDTH; ++x)
{
    for (int y=0; y<MAPHEIGHT; ++y)
    {
        mymap[x][y] = IMG_Load( some_function_that_gives_an_image_path(x, y) );
        assert(mymap[x][y]); // to spot if loading fails
    }
}

It's very likely that you'll want to share images between different tiles, so make sure you don't mess up and that every pointer in mymappoints to something real. A debugger might help spotting issues.

Last thing, if you're using some kind of asynchronous loading, you'll have to wait for your images to load before you start rendering them.

Make sure mymap is really a 2-dimensions array of size MAPWIDTH * MAPHEIGHT. E.g. if that's a plain old array of SDL_Surface pointers, its declaration should be as follows:

SDL_Surface* mymap[MAPWIDTH][MAPHEIGHT];

Then all the images stored in this array have to be loaded in memory before you call this code. That could be a simple loop, assuming you use SDL_image:

for (int x=0; x<MAPWIDTH; ++x)
{
    for (int y=0; y<MAPHEIGHT; ++y)
    {
        mymap[x][y] = IMG_Load( some_function_that_gives_an_image_path(x, y) );
        assert(mymap[x][y]); // to spot if loading fails
    }
}

It's very likely that you'll want to share images between different tiles, so make sure you don't mess up and that every pointer in mymappoints to something real. A debugger might help spotting issues.

Last thing, if you're using some kind of asynchronous loading, you'll have to wait for your images to load before you start rendering them.

Source Link
Laurent Couvidou
  • 9.2k
  • 2
  • 42
  • 58

Make sure mymap is really a 2-dimensions array of size MAPWIDTH * MAPHEIGHT. E.g. if that's a plain old array of SDL_Surface pointers, it's declaration should be as follows:

SDL_Surface* mymap[MAPWIDTH][MAPHEIGHT];

Then all the images stored in this array have to be loaded in memory before you call this code. That could be a simple loop, assuming you use SDL_image:

for (int x=0; x<MAPWIDTH; ++x)
{
    for (int y=0; y<MAPHEIGHT; ++y)
    {
        mymap[x][y] = IMG_Load( some_function_that_gives_an_image_path(x, y) );
        assert(mymap[x][y]); // to spot if loading fails
    }
}

It's very likely that you'll want to share images between different tiles, so make sure you don't mess up and that every pointer in mymappoints to something real. A debugger might help spotting issues.

Last thing, if you're using some kind of asynchronous loading, you'll have to wait for your images to load before you start rendering them.