简体   繁体   中英

SDL Tiling part 2

I earlier posted a problem in SDL complaining that my function would always return a null. I got an answer to my problem that definitely solved something, but not everything. This is the post: Tiling System C++ SDL

I added the following to my map.cpp file:

//Make a temporary map to draw the tiles to
Uint32 rmask, gmask, bmask, amask;
if ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) {
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
}
else {
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
}
SDL_Surface* temp_map = SDL_CreateRGBSurface(SDL_SWSURFACE, MAP_WIDTH, MAP_HEIGHT, 32, rmask, gmask, bmask, amask);

Although the image no longer returns null, my function still does not print the tiles onto the image at all. The image remains completely transparent.

Your code should generate a valid test_map , see SDL_CreateRGBSurface documented here .

One thing to keep in mind is that your SDL_Rect in apply_surface does not have all of its values set. SDL_Rect does not have a default constructor zeroing the memory. You only assign the x and y but never the w and h , which means that your w and h will contain garbage. You should initialize these values to your source surface's w and h as suggested in this example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM