2019年06月01日

androidのバックボタンに対応する【RPGツクールMV+cordova】

androidでテストして頂いている方から
「バックキーに対応した方が良い」というフィードバックを頂いた。

自分はandroid端末を持っておらず、エミュレーターソフトで動作確認していたので気付かなかったのだけど、androidにはバックキーというものがあるらしい。
よく見たらエミュレータにもついていた。

どうやらcordovaでは、何もせずデフォルトの状態だと、バックキーを押した時点でアプリが終了してしまうらしい。
(最小化のような動きをするが、再度立ち上げるとアプリが再起動しているので、エラー落ちしている可能性が高い)

ので、対応しました。

// androidのバックキーイベント
document.addEventListener("backbutton", backKeyEvent, false);
function backKeyEvent() {
    if(window.confirm('アプリを終了しますか?')) {
        navigator.app.exitApp();
    }
}

index.phpで呼んでいるcommon.jsの中辺りに、これを記述するだけです。

本当は、タイトル画面だったら上記、
それ以外のゲーム画面だったらコモンイベントなんかを呼んで確認後にタイトルに戻る処理をつくろうと思ったんですが、イベントの最中だったりすると中断イベント(コモンイベント)を呼び出せなかったりして微妙なので、上記で統一しました。

こうなります。

これで安心。

Good morning! You have stated this so eloquently. I have shared it with a number of pediatric cardiac surgeons. Thank you. Gayel Rowland Brine
<strong>kamagra singapour acheter</strong>

acheter en ligne pas cher kamagra
<strong>buying enclomiphene cost uk</strong>

cheap enclomiphene australia suppliers
<strong>cheapest buy androxal generic uk next day delivery</strong>

order androxal usa sales
<strong>get dutasteride australia over the counter</strong>

order dutasteride low price
<strong>ordering flexeril cyclobenzaprine usa cheap</strong>

buy cheap flexeril cyclobenzaprine generic flexeril cyclobenzaprine
<strong>how to buy gabapentin buy online usa</strong>

purchase gabapentin generic tablets
<strong>purchase fildena cheap europe</strong>

online order fildena generic good
<strong>drug itraconazole for women</strong>

buy cheap itraconazole uk in store
<strong>order staxyn cheap online pharmacy</strong>

how to order staxyn generic where to buy
<strong>buying avodart purchase from uk</strong>

order avodart buy sydney
<strong>online order xifaxan generic health</strong>

how to order xifaxan canada drugs
<strong>get rifaximin generic when will be available</strong>

how to order rifaximin uk buy online
<strong>porovnat cenu kamagra</strong>

kamagra bez lékařského předpisu

コメントを残す