由於某些原因,SDL拒絕呈現圖像。我不明白爲什麼,它正在讓我在正在開發的2D遊戲中取得進步。一切都妥善鏈接,等等。這裏是我的代碼:C++和SDL:顯示圖像時出現問題?
//main.cpp
#include "main.h"
void game::createWindow(const int SCREEN_W, const int SCREEN_H, const char* SCREEN_NAME)
{
buffer = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, NULL);
SDL_WM_SetCaption(SCREEN_NAME, NULL);
}
void game::enterLoop()
{
while(Running == true)
{
SDL_BlitSurface(zombie, NULL, buffer, NULL);
SDL_Flip(buffer);
while(SDL_PollEvent(&gameEvent))
{
if(gameEvent.type == SDL_QUIT)
{
Running = false;
}
}
}
}
void game::loadContent()
{
zombie = SDL_LoadBMP("zombie.bmp");
}
int main(int argc, char* argv[])
{
game gameObj;
SDL_Init(SDL_INIT_EVERYTHING);
gameObj.createWindow(960, 600, "uShootZombies");
gameObj.loadContent();
gameObj.enterLoop();
SDL_Quit();
return 0;
}
//main.h
#include <SDL.h>
#include <fstream>
#include <string>
using namespace std;
class game
{
public:
void createWindow(const int SCREEN_W, const int SCREEN_H, const char* SCREEN_NAME);
void enterLoop();
void loadContent();
game()
{
Running = true;
}
~game()
{
SDL_FreeSurface(buffer);
SDL_FreeSurface(background);
SDL_FreeSurface(player);
SDL_FreeSurface(zombie);
}
private:
SDL_Surface* buffer;
SDL_Surface* background;
SDL_Surface* player;
SDL_Surface* zombie;
SDL_Event gameEvent;
bool Running;
};NU
你檢查,如果你的表面加載後是有效的? – 2010-11-12 04:41:34
我不完全錯誤檢查,你可以看到。不過,我嘗試使用非常基本的「int main-only」代碼,它只是簡單地加載一個有效的圖像並將其放到屏幕上。那裏也沒有運氣。如果您想查看我使用的代碼,請參閱lazy foo的sdl教程並查看第一個教程(這不是「設置SDL」的教程) – Lemmons 2010-11-12 08:05:43