私はプロジェクトのような小さな「ゲーム」を練習として取り組んでおり、私のフレームレートを3FPSにまで下げました。描かれているのはスクリーン充填タイルとミニマップだけです。 これは、問題がミニマップにあることが判明しました.60 FPSで上限がありません。しかし残念ながら、私は私の描画機能...マップとミニマップ(SFML)のみを使用した低フレームレート
本当の問題がそれであるかを調べるのに十分な経験を積んないよ:
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テクスチャの代わりにミニマップを描画するために使用されます。
だから私はミニマップの描画を省略する場合、唯一のマップ自体を描き、それは私が望むことができるよりも多くの流体だ...
すべてのヘルプは歓迎です!
あなたの問題は何ですか?これは60fpsで制限されていますか? – snb
これは3fpsで動作します。これは、ミニマップ描画ループのためです。私がそれを取り除くと、それは60で動作します。これは問題ありません。 – nepp95
ビューを使用してミニマップを描画するのではなく、ミニマップを[レンダリングテクスチャ](https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1RenderTexture.php)にレンダリングする方が、 )そして、あなたが望む場所でそのテクスチャを描画します。 – 0x5453