Class: TonGame

ウィンドウサイズ、仮想解像度、フルスクリーン切り替え、FPS計測などを管理します。

Methods

int GetVirtualWidth()

仮想画面の幅を取得します。

int GetVirtualHeight()

仮想画面の高さを取得します。

int GetWindowWidth()

現在のウィンドウ幅を取得します。

int GetWindowHeight()

現在のウィンドウ高さを取得します。

TimeSpan GetTotalGameTime()

ゲーム開始からの総経過時間を取得します。

bool GetIsFullScreen()

現在のフルスクリーン状態を取得します。

float GetUpdateFPS()

現在のUpdate FPS(論理フレームレート)を取得します。

float GetDrawFPS()

現在のDraw FPS(描画フレームレート)を取得します。

void SetWindowSize(int width, int height)

実際のウィンドウサイズを設定します。

void SetWindowTitle(string title)

ウィンドウのタイトルバーのテキストを設定します。

void SetMouseVisible(bool visible)

マウスカーソルの表示・非表示を設定します。

void SetVirtualResolution(int width, int height)

ゲームロジックが使用する仮想解像度を設定します。描画時にウィンドウサイズに合わせて自動的にスケール(レターボックス付き)されます。

void SetResizable(bool enable)

ウィンドウのリサイズ(最大化ボタン含む)をユーザーに許可するかを設定します。
有効にすると、ユーザーがウィンドウ枠をドラッグしてサイズ変更できるようになります。ゲーム画面はアスペクト比を維持して拡大縮小されます。

void ToggleFullScreen(bool isFullscreen)

ウィンドウモードとフルスクリーンモードを切り替えます。

Sample Code

// Initialize window settings
// Set actual window size to 1280x720
Ton.game.SetWindowSize(1280, 720);

// Set virtual resolution (game logic size) to 640x360
Ton.game.SetVirtualResolution(640, 360);

// Toggle Fullscreen on Start button
if (Ton.input.IsJustPressed("Start"))
{
    Ton.game.ToggleFullScreen(!Ton.game.GetIsFullScreen());
}

// Log current FPS (Update/Draw)
float updateFps = Ton.game.GetUpdateFPS();
float drawFps = Ton.game.GetDrawFPS();
Ton.log.Info($"FPS - Update: {updateFps}, Draw: {drawFps}");

// Get mouse position converted to virtual coordinates
Vector2 mouseWin = Mouse.GetState().Position.ToVector2();
Vector2 mouseVirtual = Ton.game.ConvertWindowToVirtual(mouseWin);