Skip to main content

App

Description:

  A record representing an application singleton instance.

frame​

Type: Readonly Field.

Description:

  The current passed frame number.

Signature:

const frame: integer

bufferSize​

Type: Readonly Field.

Description:

  The size of the main frame buffer texture used for rendering.

Signature:

const bufferSize: Size

visualSize​

Type: Readonly Field.

Description:

  The logic visual size of the screen. The visual size only changes when application window size changes. And it won't be affacted by the view buffer scaling factor.

Signature:

const visualSize: Size

devicePixelRatio​

Type: Readonly Field.

Description:

  The ratio of the pixel density displayed by the device Can be calculated as the size of the rendering buffer divided by the size of the application window.

Signature:

const devicePixelRatio: number

App.Platform​

Type: Enumeration.

Description:

  An enumerated type representing the platform the game engine is running on.

Signature:

enum Platform
"Windows"
"Android"
"macOS"
"iOS"
"Linux"
"Web"
"Unknown"
end

platform​

Type: Readonly Field.

Description:

  The platform the game engine is running on.

Signature:

const platform: Platform

version​

Type: Readonly Field.

Description:

  The version string of the game engine. Should be in format of "v0.0.0.0".

Signature:

const version: string

deps​

Type: Readonly Field.

Description:

  The dependencies of the game engine.

Signature:

const deps: string

deltaTime​

Type: Readonly Field.

Description:

  The time in seconds since the last frame update.

Signature:

const deltaTime: number

elapsedTime​

Type: Readonly Field.

Description:

  The elapsed time since current frame was started, in seconds.

Signature:

const elapsedTime: number

totalTime​

Type: Readonly Field.

Description:

  The total time the game engine has been running until last frame ended, in seconds. Should be a contant number when invoked in a same frame for multiple times.

Signature:

const totalTime: number

runningTime​

Type: Readonly Field.

Description:

  The total time the game engine has been running until this field being accessed, in seconds. Should be a increasing number when invoked in a same frame for multiple times.

Signature:

const runningTime: number

rand​

Type: Readonly Field.

Description:

  A uniformly distributed 32-bit unsigned integer generated by the Mersenne Twister engine, in the inclusive range 0 to 4,294,967,295. This value is not normalized to [0, 1]. Divide it by 4,294,967,295 when a normalized random value is needed. The same seed produces the same sequence on every platform.

Signature:

const rand: integer

maxFPS​

Type: Readonly Field.

Description:

  The maximum valid frames per second the game engine is allowed to run at. The max FPS is being inferred by the device screen max refresh rate.

Signature:

const maxFPS: integer

debugging​

Type: Readonly Field.

Description:

  Whether the game engine is running in debug mode.

Signature:

const debugging: boolean

testNames​

Type: Readonly Field.

Description:

  An array of test names of engine included C++ tests.

Signature:

const testNames: {string}

locale​

Type: Field.

Description:

  The system locale string, in format like: zh-Hans, en.

Signature:

locale: string

themeColor​

Type: Field.

Description:

  A theme color for Dora SSR.

Signature:

themeColor: Color

seed​

Type: Field.

Description:

  A random number seed.

Signature:

seed: integer

targetFPS​

Type: Field.

Description:

  The target frames per second the game engine is supposed to run at. Only works when fpsLimited is set to true.

Signature:

targetFPS: integer

fpsLimited​

Type: Field.

Description:

  Whether the game engine is limiting the frames per second. Set fpsLimited to true, will make engine run in a busy loop to track the precise frame time to switch to the next frame. And this behavior can lead to 100% CPU usage. This is usually common practice on Windows PCs for better CPU usage occupation. But it also results in extra heat and power consumption.

Signature:

fpsLimited: boolean

idled​

Type: Field.

Description:

  Whether the game engine is currently idled. Set idled to true, will make game logic thread use a sleep time and going idled for next frame to come. Due to the imprecision in sleep time. This idled state may cause game engine over slept for a few frames to lost. idled state can reduce some CPU usage.

Signature:

idled: boolean

fullScreen​

Type: Field.

Description:

  Whether the game engine is running in full screen mode. It is not available to set this property on platform Android and iOS.

Signature:

fullScreen: boolean

alwaysOnTop​

Type: Field.

Description:

  Whether the game engine window is always on top. It is not available to set this property on platform Android and iOS.

Signature:

alwaysOnTop: boolean

devMode​

Type: Field.

Description:

  Whether the game engine is running in development mode. The App:shutdown() function will emit a "AppEvent" global event with type "Shutdown" instead of shutting down the game engine.

Signature:

devMode: boolean

winSize​

Type: Field.

Description:

  The application window size. May differ from visual size due to the different DPIs of display devices. It is not available to set this property on platform Android and iOS.

Signature:

winSize: Size

winPosition​

Type: Field.

Description:

  The application window position. It is not available to set this property on platform Android and iOS.

Signature:

winPosition: Vec2

runTest​

Type: Function.

Description:

  A function that runs an specific C++ test included in the engine.

Signature:

runTest: function(self: App, name: string): boolean

Parameters:

ParameterTypeDescription
namestringThe name of the test to run.

Returns:

Return TypeDescription
booleanWhether the test ran successfully.

openURL​

Type: Function.

Description:

  A function that opens a URL in the system default browser.

Signature:

openURL: function(self: App, url: string)

Parameters:

ParameterTypeDescription
urlstringThe URL to open.

install​

Type: Function.

Description:

  A function used for self updating the game engine.

Signature:

install: function(self: App, path: string)

Parameters:

ParameterTypeDescription
pathstringThe path to the new engine file.

saveLog​

Type: Function.

Description:

  A function used for save all the log to a file.

Signature:

saveLog: function(self: App, path: string): boolean

Parameters:

ParameterTypeDescription
pathstringThe path to save the log file.

Returns:

Return TypeDescription
booleanWhether the log file was saved successfully.

saveScreenshot​

Type: Function.

Description:

  Requests a screenshot of the main backbuffer.

Signature:

saveScreenshot: function(self: App, filename: string): string

Parameters:

ParameterTypeDescription
filenamestringThe output path, with an optional .tga extension.

Returns:

Return TypeDescription
stringThe actual TGA output path, or an empty string on failure.

openFileDialog​

Type: Function.

Description:

  Opens a file dialog. Desktop supports optional extension filters; mobile selects ZIP files only. Folder selection is desktop-only.

Signature:

openFileDialog: function(self: App, folderOnly: boolean, callback: function(path: string), extensions?: string)

Parameters:

ParameterTypeDescription
folderOnlybooleanWhether the file dialog is only for selecting folders.
extensionsstring (optional)Comma-separated extensions without dots, e.g. "zip" or "png,jpg". Omit for default filters. Ignored for folders and on mobile.
callbackfunctionThe callback function to be called when the file dialog is closed. The callback function should accept a string parameter which is the path of the selected file or folder. Get empty string if the user canceled the dialog.

estimateTokens​

Type: Function.

Description:

  A function that estimates how many LLM tokens a text will roughly consume. By default, ASCII characters are counted at roughly 0.4 token each, and non-ASCII characters are counted at 2 tokens each.

Signature:

estimateTokens: function(self: App, text: string, asciiTokensPerChar?: number --[[0.4]], nonAsciiTokensPerChar?: number --[[2.0]]): integer

Parameters:

ParameterTypeDescription
textstringThe text to estimate.
asciiTokensPerCharnumberOptional override for ASCII characters. Default is 0.4.
nonAsciiTokensPerCharnumberOptional override for non-ASCII characters. Default is 2.0.

Returns:

Return TypeDescription
integerThe estimated token count.

shutdown​

Type: Function.

Description:

  A function that shuts down and exits the game engine. When devMode is set to true, the shutdown function will only emit a "AppEvent" global event with type "Shutdown", instead of shutting down the game engine. It is not working and acts as a dummy function for platform Android and iOS to follow the specification of how mobile platform applications should operate.

Signature:

shutdown: function(self: App)