' put flip test ' put に与える画像幅をマイナス値にすれば反転描画できるかなと期待したが ' そんな美味しい話はなかった #ifdef __FB_WIN32__ ' Windowsの場合、mmsystemを利用 #include "windows.bi" #include "win/mmsystem.bi" #endif ' fbgfxモードを使う #Include "fbgfx.bi" Using fb ' 時間計測用の変数 Dim As Double start_time, prev_time, now_time, delta, one_frame, next_time Dim As Integer frame_count Dim As String fps_text = "FPS" Dim As Integer scrw, scrh ' ウインドウサイズ Dim As Integer imgw, imgh ' 画像サイズ chdir exepath() ' カレントディレクトリを exeファイルのある場所にする ' ウインドウサイズと色深度を指定 scrw = 512 scrh = 288 Screenres scrw, scrh, 32 ' 画像読み込み。FreeBASIC標準のbmp読み込みを使う場合 Dim img As any ptr = ImageCreate(128, 64) Bload "obj.bmp", img imageinfo img, imgw, imgh ' 画像の幅と高さを取得 #ifdef __FB_WIN32__ timeBeginPeriod(1) ' タイマー精度を1msecに向上 #endif Dim As Double MAX_FPS = 60.0 ' FPS one_frame = 1.0 / MAX_FPS ' 1フレームあたりの本来の時間 start_time = Timer ' 開始時間を取得 prev_time = start_time frame_count = 0 Dim As Boolean running = True Dim As Double x, y x = scrw / 2 y = scrh / 2 Dim As Double anime_t = 0.0 ' メインループ While (running) ' 前回フレームから何秒経過したか取得。単位は秒(小数点以下有り) now_time = Timer delta = now_time - prev_time prev_time = now_time next_time = now_time + one_frame If delta < 0 Then delta = one_frame If now_time >= start_time Then If (now_time - start_time) >= 1.0 Then ' 1秒経過したのでFPSを取得 fps_text = "FPS: " & frame_count start_time += 1.0 frame_count = 0 End If Else start_time = now_time End If frame_count += 1 ' ESCキー、qキー、ウインドウの閉じるボタンを検出 Dim As String k = inkey$ If k = Chr$(27) Or k = "q" Or k = Chr$(255) + "k" Then running = False ' メインループ終了 End If anime_t += delta ' アニメ表示用カウンタを更新 ScreenLock ' 描画開始 color RGB(255, 255, 255), RGB(52, 164, 255) cls ' 画面クリア ' 画像を描画 Dim As Integer n, sx, sy, sw, sh n = Int(anime_t / 0.5) Mod 2 ' 0 or 1 sw = (imgw / 2) ' 幅 sh = imgh ' 高さ sx = 0 ' 描画元 x sy = 0 ' 描画元 y If n = 1 Then sx += sw sw = -sw End If Put (x - (sw / 2), y - (sh / 2)), img, (sx, sy) - Step(sw, sh), TRANS ' 文字列を描画 Draw String (10, 10), fps_text Draw String (scrw / 2 - (8 * 6), scrh * 0.8), "HELLO WORLD" ScreenUnlock ' 描画終了 If Timer < next_time Then ' 本来の1フレーム時間がまだ経過してないので sleep させる Dim As Double wait_ms = (next_time - Timer) * 1000.0 If wait_ms > 0.0 Then sleep wait_ms End If Wend While Inkey <> "": Wend ' キーバッファを空にする #ifdef __FB_WIN32__ timeEndPeriod(1) ' タイマー精度を本来のスペックに戻す #endif ImageDestroy img ' 画像を使い終わったので破棄