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);
...
我只是通過將我的代碼放入while循環來修復它,完全忘了這一點。該循環也翻轉表面,所以你的答案是正確的。謝謝 – Chris 2012-07-09 21:54:29
很高興我能幫上忙 – reagan 2012-07-09 21:55:23