Reputation: 853
I'm making Pacman game in opengl and I want to move my pacman in the game represented by a matrix.
The matrix have 16x16 and i put 4's when I whant to draw the walls, 3 for the small spheres and 2 for the pacman.
In the main class of my project I read a key from keyboard and i send the information to the class I defined the game. In that class I have this function:
void boardGame::refreshPacman(int n, int m)
{
int x, y;
(* pacman).movePacman(n, m); // This is working, it send information to class Pacman. In there I store the n (x axe) and m(y axe), and i get the next coordinates where pacman should translate.
x = (* pacman).getPacX(); // get coordinate of the old pacman
y = (* pacman).getPacY(); // get coordinate of the old pacman
board[x][y] = 0; // delete old information of pacman in matrix
x += n; // set the coordinates of x axis for new pacman
y += m; // set the coordinates of y axis for new pacman
wall[x][y] = 2; // insert the information of new pacman in matrix
pac->redraw (x, y, 0.5); // construct the new pacman
}
Pacman It's not beeing erased. Can you tell me what do I need to do next, and waht am I doing wrong?
Upvotes: 0
Views: 1259
Reputation: 162164
Pacman It's not beeing erased. Can you tell me what do I need to do next, and waht am I doing wrong?
OpenGL is not a scenegraph (this is becomming the one statement I'm apparently make in almost every answer). It's a drawing API, which allows you to draw dancy points, lines and triangles. There's no concept of "geometric objects".
If you change something: Clear the old picture and draw a new one!
Upvotes: 4
Reputation: 22011
Use the ->
operator with class pointers.
(* pacman).movePacman(n, m);
Should be:
pacman->movePacman(n,m);
To erase the earlier pacman, try redrawing the screen before adding the new one. Also, does the pacman destructor internally also end the rendering of the pacman image/sprite?
Upvotes: 2