2012-07-09 102 views
0

我的代碼並不真正工作(沒有錯誤,但矩形未顯示)。 我有3個類:CFramework,CRectangle,CGame。 最新錯誤/缺失?使用SDL_FillRect創建矩形

我CFramework類啓動SDL並設置視頻模式等

CRectangle.hpp:

#ifndef RECTANGLE_HPP 
#define RECTANGLE_HPP 

#include "Framework.hpp" 

class CRectangle 
{ 
    public:  
     CRectangle(); 
     void createRectangle (int x, int y, int width, int height, int r, int g, int b); 

    private: 
     SDL_Surface *m_pScreen; // Pointer at the screen of CFramework 
     SDL_Rect m_Rect; 
}; 


#endif 

CRectangle.cpp:

#include "Rectangle.hpp" 


// Konstruktor 
// 
// Aufgabe: Zeiger auf Screen holen 
// 
CRectangle::CRectangle() 
{ 
    // Zeiger auf Screen holen 
    m_pScreen = g_pFramework->GetScreen(); 

} // Konstruktor 

// createRectangle 
// 
// Aufgabe: Viereck erstellen 
// 
void CRectangle::createRectangle (int x, int y, int width, int height, int r, int g, int b) 
{ 
     m_Rect.x = x; 
     m_Rect.y = y; 
     m_Rect.w = width; 
     m_Rect.h = height; 
     SDL_FillRect(m_pScreen, &m_Rect, SDL_MapRGB(m_pScreen->format, r, g, b)); 
} // createRectangle 

CGame.cpp :

... // just the important stuff 
    m_pRectangleMenu = new CRectangle; 
    m_pRectangleMenu->createRectangle(100,100,400,400,233,34,34); 
... 

回答

1
// just the important stuff 
m_pRectangleMenu = new CRectangle; 
m_pRectangleMenu->createRectangle(100,100,400,400,233,34,34); 

嘛,因爲你並沒有包括 「SDL_Flip(screen_variable)」 ......也許這是你的問題。如果沒有,你應該發佈到SDL_Flip()。

里根

+0

我只是通過將我的代碼放入while循環來修復它,完全忘了這一點。該循環也翻轉表面,所以你的答案是正確的。謝謝 – Chris 2012-07-09 21:54:29

+0

很高興我能幫上忙 – reagan 2012-07-09 21:55:23