■gb.frameCount
Gamebuimo.hライブラリのgb.frameCount変数は、gb.update()関数が呼び出されるたびにインクリメント※1されるので、プログラムの実行が開始されてからレンダリングされるフレーム数を表します。時間を測定するには、millis()よりも優先されるべきです。これはモジュロ※2を使用して周期的なイベントタイミング(アニメーションビットマップのような)に使用できます。
※1:インクリメント(increment)とは、変数の値を1増やす演算の事
※2:モジュロ (modulo)とは、割り算の余りの事
■使用例
gb.frameCount変数を使ったArduinoIDEのプログラム例は図1の通りです。
このプログラムを実行するとsetup関数中のgb.begin関数でGamebuinoオブジェクトを初期化し、gb.titleScreen関数で画面に「My first game」と表示します。
スタート画面でキーボードの「K」(GamebuinoのA)ボタンを押すと画面下にgb.popup関数により「Let's go!」と表示され、同時にgb.display.println関数により画面左上に「Hello world!」と表示され、その下にgb.frameCount変数の値がリアルタイムに更新されます。
参考に図1プログラムをHEXファイルに変換し、それをSimbuino4Webでエミュレートした結果を図2に示します。
//imports the SPI library (needed to communicate with Gamebuino's screen) #include <SPI.h> //imports the Gamebuino library #include <Gamebuino.h> //creates a Gamebuino object named gb Gamebuino gb; // the setup routine runs once when Gamebuino starts up void setup() { // initialize the Gamebuino object gb.begin(); //display the main menu: gb.titleScreen(F("My first game")); gb.popup(F("Let's go!"), 100); } // the loop routine runs over and over again forever void loop() { //updates the gamebuino (the display, the sound, the auto backlight... everything) //returns true when it's time to render a new frame (20 times/second) if (gb.update()) { //prints Hello World! on the screen gb.display.println(F("Hello World!")); //declare a variable named count of type integer : int count; //get the number of frames rendered and assign it to the "count" variable count = gb.frameCount; //prints the variable "count" gb.display.println(count); } }
図2:プログラム実行結果
■構文
gb.frameCount()変数のパラメータ
■パラメータ
ありません
■戻り値
プログラムの実行が開始されてからレンダリングされたフレームの数(デフォルトでは毎秒20フレーム)(変数の型:unsigned long)