使用 SDL2 渲染平铺地图的最快方法
Fastest way to render a tiled map with SDL2
我正在寻找一种非常快速的方法来使用 SDL2 渲染具有三层的平铺地图。我正在使用SDL_RenderCopy但它很慢...
好的,我已经找到了我需要的东西,所以我会在这里解释一下。
我实际上有四个图层,我曾经在一个简单的 for 循环中渲染它们。事实上,for 循环并不是渲染平铺地图的好方法。
最好的方法是在主渲染循环之前将每个图层渲染成一个大纹理,然后将每个大纹理渲染到屏幕上。for 循环需要花费大量时间来处理,但是,渲染大纹理非常快。
看看下面的代码,考虑到"bigTexture"是一个图层,而"width"和"height"是该图层的大小。
Uint32 pixelFormat;
SDL_QueryTexture(tileset, &pixelFormat, NULL, NULL, NULL);
SDL_Texture *bigTexture = SDL_CreateTexture(renderer, pixelFormat, SDL_TEXTUREACCESS_TARGET, width, height);
SDL_SetRenderTarget(renderer, bigTexture);
// Put your for loop here
完成后,我们将图层加载到一个大纹理中。让我们看看如何渲染它。
SDL_SetRenderTarget(renderer, NULL);
// Create a SDL_Rect which defines the big texture's part to display, ie the big texture's part visible in the window.
// Display the big texture with a simple SDL_RenderCopy
就这样。现在,您可以非常快速地渲染平铺地图。
相关文章:
- 在 c++ 中,有一种方法可以创建一个包含地图作为值的树状地图?
- C++将所有元素从矢量复制到地图/unordered_map的最佳方法
- 如何调用返回双精度或字符串并将其保存在地图上但作为对象的类的方法
- 无法理解使用这张地图背后的证明<>方法
- 获取地图值作为向量的最佳方法是什么
- 将信息从 2D 矢量传输到地图的最快方法是什么
- 在游戏地图上选择100种情况的最佳方法(MFC,CPoint)
- C - 搜索地图中具有相同值的所有键的最快方法是什么
- 删除多地图中重复项的有效方法
- 使用 SDL2 渲染平铺地图的最快方法
- 按值在地图中查找 - 方法在速度方面的偏好
- 清理地图中所有共享指针的正确方法是什么
- 将自定义类型作为地图的可能键的可能方法有哪些
- 获取按地图值排序的映射键向量的最快方法
- 如何将地图作为参数传递并在此方法中添加
- 对基于地图C++集合重新排序的有效方法
- 一种打印多地图地图的方法
- C++标准::地图比较方法
- 插入标准::地图的最佳方法
- 清除地图和删除内容的最简洁的方法是什么?