0

ウィンドウに画像を追加したい。これは私のコードです:

SDL_Surface* bitmap = SDL_LoadBMP("bat.bmp");

// Part of the bitmap that we want to draw
SDL_Rect source;
source.x = 24;
source.y = 63;
source.w = 65;
source.h = 44;

// Part of the screen we want to draw the sprite to
SDL_Rect destination;
destination.x = 100;
destination.y = 100;
destination.w = 65;
destination.h = 44;

SDL_Event event;
bool gameRunning = true;

while (gameRunning)
{
    if (SDL_PollEvent(&event))
    {
        if (event.type == SDL_QUIT)
        {
            gameRunning = false;
        }
    }

    SDL_BlitSurface(bitmap, &source, screen, &destination);

    SDL_Flip(screen);
}

ウィンドウが読み込まれると、ウィンドウが黒くなり、画像が表示されなくなります。どうしたの?

4

1 に答える 1

0

あなたのコードは大丈夫です。

SDL_Surface* bitmap = SDL_LoadBMP("bat.bmp");が適切なアドレスを返すかどうかを確認しましたか?
イメージのロードに失敗すると、NULL が返されます。

SDL_Surface にも問題がある可能性がありますがscreen、コードには示されていません。

于 2013-06-07T12:10:07.843 に答える