c++ - 如何将 c++/opengl 中的对象移动到新位置并删除旧对象

标签 c++ opengl

我正在用 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/

相关文章:

c++ - 带有小数组的删除 [] 上的 SIGTRAP

c++ - OpenGL 纹理加速 - 查看相关纹理

c++ - GLFW:创建窗口时出现 'WGL: The driver does not appear to support OpenGL' 错误

c++ - 动态添加对象

c - 带有原始数据的头文件的目的是什么?

c++ - 通过 make_shared 停止堆分配

c++ - 将 QRegExValidator 用于 QLineEdit

python - 如何在已经加载的 OpenGL 场景中添加顶点?

c++ - 使用 G++ 编译时出现 "Undefined Refrence to Foo"

c++ - C++中AES NI加密的正确方法