0

さて、fpsを60にしようとしていますが、現在は20前後です。このコードを高速化するにはどうすればよいですか?注:これはsfmlを使用したc++です。

    App.Clear();
    for(int x = 0; x < lv.width; x++){
        for(int y = 0; y < lv.height; y++){

            int tileXCoord = 0;
            int tileYCoord = 0;
            int tileSheetWidth = tilemapImage.GetWidth() / lv.tileSize;

            if (lv.tile[x][y] != 0)
            {
                tileXCoord = lv.tile[x][y] % tileSheetWidth;
                tileYCoord = lv.tile[x][y] / tileSheetWidth;
            }

            tilemap.SetSubRect(sf::IntRect(tileXCoord * lv.tileSize, tileYCoord * lv.tileSize, (tileXCoord * lv.tileSize) + lv.tileSize, (tileYCoord * lv.tileSize) + lv.tileSize));
            tilemap.SetPosition(x * lv.tileSize, y * lv.tileSize);
            App.Draw(tilemap);
        }
    }

    playerSprite.SetSubRect(sf::IntRect(player.width * player.frame, player.height * player.state,
                                   (player.width * player.frame) + player.width, (player.height * player.state) + player.height));
    playerSprite.SetPosition(player.x, player.y);

    App.Draw(playerSprite);

    if(player.walking){
        if(player.frameDelay >= 0)
            player.frameDelay--;

        if(player.frameDelay <= 0){

            player.frame++;
            player.frameDelay = 10;

            if(player.frame >= 4)
                player.frame = 0;
        }
    }


    for(int x = 0; x < lv.width; x++){
        for(int y = 0; y < lv.height; y++){

            int tileXCoord = 0;
            int tileYCoord = 0;
            int tileSheetWidth = tilemapImage.GetWidth() / lv.tileSize;

            if (lv.ftile[x][y] != 0)
            {
                tileXCoord = lv.ftile[x][y] % tileSheetWidth;
                tileYCoord = lv.ftile[x][y] / tileSheetWidth;
            }

            tilemap.SetSubRect(sf::IntRect(tileXCoord * lv.tileSize, tileYCoord * lv.tileSize, (tileXCoord * lv.tileSize) + lv.tileSize, (tileYCoord * lv.tileSize) + lv.tileSize));
            tilemap.SetPosition(x * lv.tileSize, y * lv.tileSize);
            App.Draw(tilemap);
        }
    }


    App.Display();
4

2 に答える 2

1

タイルではなく、レベルのピクセルを反復処理しているようです。のように書き換えます。

 ///get the width of a tile
// get the height of a tile
int tileWidth = tilemapImage.getWidth();
int tileHeight = tilemapImage.getHeight();

//find the number of tiles vertically and horizontally, by dividing
// the level width by the number of tiles
int xTiles = lv.width / tileWidth;
int yTiles = lv.height / tileHeight();

for (int x = 0; x < xTiles; x++) {
    for (int y = 0; y < yTiles; y++) {
        // Do your calculations here

        //ie: if(Walking) { draw_walk_anim; }
        // draw_tile[x][y];

        tilemap.SetPosition(x * tileWidth, y * tileHeight);
    }
}
于 2011-04-03T14:40:31.860 に答える
0

私はこの分野の専門知識が不足していますが、取得しているパラメーターに基づいて、タイルごとにタイルマップを描画しています。変更されたのはせいぜい 1 つのタイルであっても、タイルマップ全体を再描画しているように見えます。

App.Draw(tilemap); のみを呼び出す方法 すべての行の後、またはおそらく画面全体が物事に影響を与えるように設定した後。

于 2011-04-03T14:35:46.367 に答える