LoginSignup
1
0

More than 1 year has passed since last update.

スマホの低電力モードだとpixi.jsのFPSが半分になる問題を無理やり解決する

Last updated at Posted at 2021-05-21

pixi.jsにはtickerという機能があり、ほとんどの場合においてFPS60でループ処理をしてくれる。
しかし、環境にも依るかもしれないが、スマホの「低電力モード」が発動しているとFPSが30まで低下する。

script.js
let app = new PIXI.Application({});

app.ticker.add(loop);

function loop(delta){
    console.log(app.ticker.FPS);
}

このような書き方だと、端末の状態によってループ速度が変わってしまい、いろいろなところに影響が出る。
そこで次のようにして無理やり解決を試みた。

script.js
let app = new PIXI.Application({});

app.ticker.add(loop);

function loop(delta){
    for(let i=0;i<Math.round(delta);i++){
        main();
    }
}

function main(){
    console.log(app.ticker.FPS);
}

deltaapp.ticker.deltaTimeの値であり、前のフレームから今のフレームまでの経過時間を【1/60秒】の単位で出してくれる。
もしdeltaが2に近い場合、つまりFPSが半分になっている場合は、loopの内容を2回繰り返す。
こうすれば、描画自体はもっさりとするが処理はほぼ想定通りの速度でやってくれる。

2021/06/02 試行錯誤の続き→pixi.jsでtickerのFPSが端末の状態に依存しないように見せる

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0