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 回答