-2
我有一个7 x 7的探测矩阵,它提供了一个信号,代表在该地区测量的水平。我可以在SDL中绘制7 x 7矩形的矩阵,但我无法更新颜色。
我有一个类 类探针 { public: Probe(); 〜Probe(); void SetColor(int x); void Set_id(int x,int y,int z);
void Level_id(void);cpp私有数据成员SDL_Rect无效
private:
int OldColor;
int Xcord;
int Ycord;
SDL_Rect rect; //This does not keep the rect that I create?
};
//outside all curly brackets {} I have
Probe Level[7][7];
//I initialize each instance of my class
Level[x][y].Set_id(x, y, z); and I use x and y to create and position the rectangle
// Defininlg rectangles
SDL_Rect rect = {BLOCK_W * Xcord, BLOCK_H * Ycord, BLOCK_W, BLOCK_H};
/*I get what I expected, by the way z sets the color and it is incremented so each rectangle has a different color. */
//I used function SetColor, it failed untill I regenerated rect
//in the SetColor function. I have
private:
SDL_Rect rect;
//It is private why do I need to re-create the SDL_Rect rect?
//Why is it not stored like
private:
int Xcord; // !!? Regards Ian.
//我明白。 SDL_Rect rect = {BLOCK_W * Xcord,BLOCK_H * Ycord,BLOCK_W,BLOCK_H}; //定义一个新的函数本地。 rect = {BLOCK_W * Xcord,BLOCK_H * Ycord,BLOCK_W,BLOCK_H}; //使用在类中定义的矩形作为私有:并且是全局的//类。 //很多谢伊恩。 – stanley82
rect = {BLOCK_W * Xcord,BLOCK_H * Ycord,BLOCK_W,BLOCK_H}; // \t rect.x = BLOCK_W * Xcord; // \t rect.y = BLOCK_H * Ycord; //这些都会导致段错误。 – stanley82
//我把它放在构造函数中,SetColor更新了rect [0] [0] – stanley82