低帧率,仅使用地图和小地图绘制 (SFML)
Low framerate with only map and minimap drawing (SFML)
我正在做一个像"游戏"这样的小"游戏"项目作为练习,我已经设法将帧率降低到甚至不到 3 FPS。而唯一正在绘制的是屏幕填充瓷砖和小地图。 现在我发现问题出在小地图上,没有上限为 60 FPS。但不幸的是,我没有足够的经验来找出它的真正问题是什么......
我的绘图功能:
void StateIngame::draw()
{
m_gui.removeAllWidgets();
m_window.setView(m_view);
// Frame counter
float ct = m_clock.restart().asSeconds();
float fps = 1.f / ct;
m_time = ct;
char c[10];
sprintf(c, "%f", fps);
std::string fpsStr(c);
sf::String str(fpsStr);
auto fpsText = tgui::Label::create();
fpsText->setText(str);
fpsText->setTextSize(16);
fpsText->setPosition(15, 15);
m_gui.add(fpsText);
//////////////
// Draw map //
//////////////
int camOffsetX, camOffsetY;
int tileSize = m_map.getTileSize();
Tile tile;
sf::IntRect bounds = m_camera.getTileBounds(tileSize);
camOffsetX = m_camera.getTileOffset(tileSize).x;
camOffsetY = m_camera.getTileOffset(tileSize).y;
// Loop and draw each tile
// x and y = counters, tileX and tileY is the coordinates of the tile being drawn
for (int y = 0, tileY = bounds.top; y < bounds.height; y++, tileY++)
{
for (int x = 0, tileX = bounds.left; x < bounds.width; x++, tileX++)
{
try {
// Normal view
m_window.setView(m_view);
tile = m_map.getTile(tileX, tileY);
tile.render((x * tileSize) - camOffsetX, (y * tileSize) - camOffsetY, &m_window);
} catch (const std::out_of_range& oor)
{}
}
}
bounds = sf::IntRect(bounds.left - (bounds.width * 2), bounds.top - (bounds.height * 2), bounds.width * 4, bounds.height * 4);
for (int y = 0, tileY = bounds.top; y < bounds.height; y++, tileY++)
{
for (int x = 0, tileX = bounds.left; x < bounds.width; x++, tileX++)
{
try {
// Mini map
m_window.setView(m_minimap);
tile = m_map.getTile(tileX, tileY);
sf::RectangleShape miniTile(sf::Vector2f(4, 4));
miniTile.setFillColor(tile.m_color);
miniTile.setPosition((x * (tileSize / 4)), (y * (tileSize / 4)));
m_window.draw(miniTile);
} catch (const std::out_of_range& oor)
{}
}
}
// Gui
m_window.setView(m_view);
m_gui.draw();
}
Tile
类具有在映射生成期间设置的sf::Color
类型的变量。然后使用此颜色绘制小地图,而不是用于地图本身的 16x16 纹理。
因此,当我省略小地图绘图,只绘制地图本身时,它比我希望的更流畅......
任何帮助不胜感激!
您正在为每一帧生成全新的视图。在启动时执行此操作一次就足够了。
相关文章:
- 为什么不;名字在地图上是按顺序排列的吗
- 基于多个条件处理地图中的所有元素
- 在C++中将矢量转换为嵌套地图
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 如何在QT中的自定义视频小工具t上绘制矩形
- 替换基于地图的所有引用
- 如何区分地图中的 0 和 false?
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 地图计数确实很重要,或者只是检查是否存在
- 低帧率,仅使用地图和小地图绘制 (SFML)
- 尝试绘制精灵地图时出现 SFML 错误
- Mapbox GL为什么不使用AGG进行地图绘制
- 使用内部灰泥构建器绘制地图
- 简单的地图绘制问题
- OpenGl 在图块地图C++的顶部绘制
- 使用sfml绘制平铺地图
- 绘制小地图(游戏)
- 绘制瓷砖地图正在将我的 fps 降低到爬行