0

所以,目前我正在写一个游戏,我有一个小纹理(20x20),可以填满屏幕(1680x1050)。我的玩家在这个背景上移动,都在游戏循环中。我需要我的背景是静态的并且只绘制一次,但是 SDL_RenderClear 会重绘所有区域,这会导致滞后。我怎样才能画一次,然后用我的玩家人物更新它?

4

2 回答 2

2

真的没有办法“画一次就这样” 但是有一种方法可以让你只画一部分以获得相同的结果,只需画出角色所在的背景部分,在绘制新角色之前。

更详细地说,画出英雄触及的所有“块”,哪怕只是一点点,然后将你的英雄画在它们上面。

这是一个例子:

//LocationX is the location of hero on the X axis
//LocationX /20 is the number of the first texture that is drawn on X axis
//LocationX +Width (width of hero) +20 (width of texture) this is the number of the last texture on X axis

//Now draw everything from first to last texture that is touched the hero (just calculate the Y axis the same way as X axis!)
for (int xxx = LocationX /20; xxx < LocationX +Width + 20; xxx++)
{
    for (/*Do the same for Y axis*/)
    {
        draw(texture, xxx *20, yyy *20);
    }
}
//Draw Hero here, the background is clear!
于 2013-11-29T07:12:51.573 回答
1

从字面上回答,您应该使用SDL_RenderDrawRect“清除屏幕的一部分”。

但是,您提到您在背景中有纹理 - RenderClear 不会绘制纹理,因此此描述中的某些内容似乎是错误的。

于 2013-11-29T10:12:42.950 回答