我是 C++ 和 DirectX 的新手,我来自 XNA。我开发了一款像Fly The Copter这样的游戏。我所做的是创建了一个名为 Wall 的类。在游戏运行时,我绘制了所有的墙壁。在 XNA 中,我将墙壁存储在 ArrayList 中,而在 C++ 中,我使用了向量。在 XNA 中游戏运行速度很快,而在 C++ 中运行速度非常慢。这是 C++ 代码:
void GameScreen::Update()
{
//Update Walls
int len = walls.size();
for(int i = wallsPassed; i < len; i++)
{
walls.at(i).Update();
if (walls.at(i).pos.x <= -40)
wallsPassed += 2;
}
}
void GameScreen::Draw()
{
//Draw Walls
int len = walls.size();
for(int i = wallsPassed; i < len; i++)
{
if (walls.at(i).pos.x < 1280)
walls.at(i).Draw();
else
break;
}
}
在 Update 方法中,我将 X 值减少 4。在 Draw 方法中,我调用 sprite->Draw (Direct3DXSprite)。那是在游戏循环中运行的唯一代码。我知道这是一个糟糕的代码,如果您有改进的想法,请帮忙。谢谢和对不起我的英语。