[英]Andengine low FPS on certain phones
我的游戲在大多數手機上運行良好(56 FPS),但其他游戲的運行速度約為25 FPS。 在我的游戲中,我有3個粒子系統,據我所知,問題來自於此。 我的問題:如果我檢測到FPS低於30,那么停止產生粒子是個好主意嗎? 如果FPS更高,則只需正常運行。 我不確定這是否會導致任何問題。 還有其他解決方案嗎?
我可以想到你可以做些幾件事來幫助緩解這個問題。
您可以使用您的方法來檢測fps,然后在必要時刪除粒子系統。 但是,您不必每秒輪詢一次 - 您可以每十秒左右進行一次。 如果你確實有一個低幀率,那么你知道手機會不時受到影響,所以你不需要輪詢 - 你可以降低粒子並停止輪詢。
或者,您可以使用具有幾個“級別”粒子效果的輪詢方法,因此如果它無法處理頂級,則降低下一級別的復雜性,依此類推。
此外,您甚至可以允許用戶手動調整粒子效果,即在選項菜單中允許他們將它們切換到低設置等。
也許你也可以在運行時分析devies,即有多少內核,圖形芯片等,並相應地進行調整。
確保你的粒子被優化等,所以當它們可以更小等時你沒有不必要的紋理尺寸,但我相信你可能已經做到了!
我建議你運行游戲的所有圖形功能,當它可以每秒30幀以上渲染時。 如果您看到幀率低於30,則應關閉非重要圖形,例如。 粒子。
嘗試為清單中的活動設置“android:theme =”@ style / Theme.NoBackground“。它關閉了系統背景redering。
不要偽造創建theme.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="Theme.NoBackground" parent="android:Theme">
<item name="android:windowBackground">@null</item>
</style>
</resources>
如果幀速率降低,請嘗試跳幀,但不要跳過太多幀,否則會導致糟糕的用戶體驗。 下面是確定線程是否按時執行的代碼,如果沒有,它將跳過幀(不超過5):
// desired fps
private final static int MAX_FPS = 50;
// maximum number of frames to be skipped
private final static int MAX_FRAME_SKIPS = 5;
// the frame period
private final static int FRAME_PERIOD = 1000 / MAX_FPS;
// number of frames skipped since the game started
private long totalFramesSkipped = 0l;
// number of frames skipped in a store cycle (1 sec)
private long framesSkippedPerStatCycle = 0l;
// number of rendered frames in an interval
private int frameCountPerStatCycle = 0;
private long totalFrameCount = 0l;
// the last FPS values
private double fpsStore[];
// the number of times the stat has been read
private long statsCount = 0;
// the average FPS since the game started
private double averageFps = 0.0;
long beginTime; // the time when the cycle begun
long timeDiff; // the time it took for the cycle to execute
int sleepTime; // ms to sleep (<0 if we're behind)
int framesSkipped; // number of frames being skipped
sleepTime = 0;
beginTime = System.currentTimeMillis();
framesSkipped = 0; // resetting the frames skipped
// calculate how long did the cycle take
timeDiff = System.currentTimeMillis() - beginTime;
// calculate sleep time
sleepTime = (int)(FRAME_PERIOD - timeDiff);
if (sleepTime > 0) {
// if sleepTime > 0 we're OK
try {
// send the thread to sleep for a short period
// very useful for battery saving
Thread.sleep(sleepTime);
} catch (InterruptedException e) {}
}
while (sleepTime < 0 && framesSkipped < MAX_FRAME_SKIPS) {
// we need to catch up
this.gamePanel.update(); // update without rendering
sleepTime += FRAME_PERIOD; // add frame period to check if in next frame
framesSkipped++;
}
讓我知道這個是否奏效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.