我正在用 opengl 制作吃 bean 人游戏,我想在游戏中用矩阵表示我的吃 bean 人。
矩阵有 16x16,当我想绘制墙壁时,我放了 4 个,3 个用于小球体,2 个用于吃 bean 。
在我项目的主类中,我从键盘读取一个键,并将信息发送到我定义游戏的类。在那个课上我有这个功能:
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 它并没有被删除。你能告诉我接下来我需要做什么,我哪里做错了吗?
最佳答案
Pacman It's not beeing erased. Can you tell me what do I need to do next, and waht am I doing wrong?
OpenGL 不是场景图(这是我在几乎每个答案中显然都会做出的一个声明)。它是一个绘图 API,允许您绘制漂亮的点、线和三角形。没有“几何对象”的概念。
如果你改变了什么:清除旧图片并绘制一张新图片!
关于c++ - 如何将 c++/opengl 中的对象移动到新位置并删除旧对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9648572/