0

我很难理解在 C++ 中使用 SDL 制作滚动图形程序的概念……例如,用于横向滚动游戏,或者地图大于屏幕分辨率的自上而下游戏。

基本上,我的印象是我需要将所有资源blit到虚拟表面,然后只将其中的一部分blit到屏幕上,但这似乎不起作用。这是我正在使用的代码的一部分:

    void showMap(){
        for(int y=0;y<MAP_Y;y++){
            for(int x=0;x<MAP_X;x++){
                switch(map[x][y]){
                    case 0:
                        apply_surface(x*STEP,y*STEP,tiles,full,&clips[0][0]);
                        break;
                    case 1:
                        apply_surface(x*STEP,y*STEP,tiles,full,&clips[1][0]);
                        break;
                    case 2:
                        apply_surface(x*STEP,y*STEP,tiles,full,&clips[2][0]);
                        break;
                    case 3:
                        apply_surface(x*STEP,y*STEP,tiles,full,&clips[3][0]);
                        break;
                    default:
                        apply_surface(x*STEP,y*STEP,tiles,full,&clips[4][4]);
                        break;

                }
            }
        }
        apply_surface(0,0,full,master,&vp_xy);
    }

apply_surface 的原型如下:

void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *dest, SDL_Rect* clip);

它在给定的 x,y 处使用指定的剪辑将源传送到 dest。在示例中,我有一个 SDL_Rects 数组,其中包含各种图块的位置。如果我直接将 blit 到 master(实际屏幕),则此代码有效,但尝试将 blit 到“full”然后将其中的一部分 blit 到 master 只会让我得到一个空屏幕。我在这里想念什么?

4

1 回答 1

1

Ok ok I fould what I was doing wrong.

When I created the 'full' surface, it remained null. I just discovered the command SDL_CreateRGBSurface().

Like so:

full = SDL_CreateRGBSurface(SDL_SWSURFACE,STEP*MAP_X,STEP*MAP_Y,S_BPP,0,0,0,0);

Can't blit to a null surface. I wasn't aware of this function. The more you know~

于 2012-10-11T14:20:35.560 回答