Application entry point and process-level runtime services.
App owns the runtime bootstrap sequence for the engine. It initializes Kha,
input devices, audio, default resources, shader compilation, and the main
frame loop.
In normal projects App is configured declaratively through compile-time
@:app.* metadata handled by the @:autoBuild macro on this class. The
macro collects those metadata entries, builds a kha.SystemOptions object,
and rewrites main() into a call to start.
Typical usage:
@:app.title("Game")
@:app.window(width = 750, height = 500)
@:app.framebuffer(samplesPerPixel = 2, verticalSync = false)
class Main extends s.App {
}
The example above becomes roughly:
s.App.start({
title: "Game",
window: {
width: 750,
height: 500
},
framebuffer: {
samplesPerPixel: 2,
verticalSync: false
}
}, window -> {
// original main body
});
@:app.* metadata are therefore just shortcuts for kha.SystemOptions.
The supported top-level metadata names are:
@:app.title(value:String)SetsSystemOptions.title. This is the process title and the default window title. Ifwindow.titleis omitted, Kha copies this value into it.@:app.width(value:Int)SetsSystemOptions.width. Kha treats this as a shortcut forwindow.widthand overwrites the nested window width when the value is greater than0.@:app.height(value:Int)SetsSystemOptions.height. Kha treats this as a shortcut forwindow.heightand overwrites the nested window height when the value is greater than0.@:app.window(...)SetsSystemOptions.windowusing named fields fromkha.WindowOptions.@:app.framebuffer(...)SetsSystemOptions.framebufferusing named fields fromkha.FramebufferOptions.@:app.audio(...)SetsSystemOptions.audiousing named fields from Kha's internal audio options object.
Supported @:app.window(...) fields:
title:StringWindow title. Overrides@:app.title(...)for the actual OS window caption.x:IntHorizontal window position in screen coordinates.-1lets the backend choose automatically.y:IntVertical window position in screen coordinates.-1lets the backend choose automatically.width:IntInitial client width in pixels.height:IntInitial client height in pixels.display:IntDisplay index for multi-monitor setups.-1lets the backend choose.visible:BoolWhether the window starts visible.windowFeatures:kha.WindowFeaturesBitmask of optional window capabilities. Combine flags with|.mode:kha.WindowModeWindow presentation mode.
Available kha.WindowFeatures flags for windowFeatures:
kha.WindowFeatures.NoneNo optional features.kha.WindowFeatures.FeatureResizableAllows the user to resize the window.kha.WindowFeatures.FeatureMinimizableAllows minimizing the window.kha.WindowFeatures.FeatureMaximizableAllows maximizing the window.kha.WindowFeatures.FeatureBorderlessRequests a borderless window.kha.WindowFeatures.FeatureOnTopRequests an always-on-top window.
The default Kha feature mask is:
kha.WindowFeatures.FeatureResizable
| kha.WindowFeatures.FeatureMaximizable
| kha.WindowFeatures.FeatureMinimizable
Available kha.WindowMode values for mode:
kha.WindowMode.WindowedUses a regular OS window.kha.WindowMode.FullscreenUses regular fullscreen mode.kha.WindowMode.ExclusiveFullscreenUses exclusive fullscreen mode. In Kha this is primarily meaningful on Windows and may switch the monitor resolution.
Supported @:app.framebuffer(...) fields:
frequency:IntPreferred refresh frequency in Hz. The backend may ignore unsupported values.verticalSync:BoolEnables or disables vertical sync.colorBufferBits:IntRequested color buffer precision in bits.depthBufferBits:IntRequested depth buffer precision in bits.stencilBufferBits:IntRequested stencil buffer precision in bits.samplesPerPixel:IntRequested MSAA sample count. Use1to disable multisampling.
Supported @:app.audio(...) fields:
allowMobileWebAudio:BoolHTML5-only Kha option that enablesaudio2.Audioinitialization on mobile browsers. Use this when the application must opt into mobile Web Audio behavior.
Example with less common options:
@:app.title("Game")
@:app.window(
width = 1280,
height = 720,
mode = kha.WindowMode.Windowed,
windowFeatures = kha.WindowFeatures.FeatureResizable
| kha.WindowFeatures.FeatureMaximizable
)
@:app.framebuffer(
verticalSync = true,
samplesPerPixel = 4,
depthBufferBits = 24,
stencilBufferBits = 8
)
@:app.audio(allowMobileWebAudio = true)
class Main extends s.App {}
In normal projects you usually interact with App through:
- @:app.* metadata to configure startup
- state to react to lifecycle changes
- input to access shared mouse and keyboard devices
start still exists as the low-level runtime entry point, but
direct calls are mostly useful for custom bootstraps or tooling code.
App is process-wide. It should be treated as a singleton-style service
layer, not as something instantiated manually.
See also:
kha.SystemOptions
kha.WindowOptions
kha.FramebufferOptions
kha.WindowMode
kha.WindowFeatures
Static variables
staticread onlyinput:{mouse:Mouse, keyboard:Keyboard}
Shared input devices available after startup.
This field is assigned during application initialization. Access it after
start has begun setup, not at module load time.
Static methods
staticexit():Void
Requests application shutdown.
Whether the request can be honored depends on platform support.
staticinlineoffFropFiles(dropFiles:String ‑> Void):Void
Removes a previously registered file drop handler.
Parameters:
dropFiles | Handler to remove. |
|---|
staticinlineonCopy(copy:() ‑> String):Void
Registers a copy handler.
Parameters:
copy | Called when the platform requests copy text. |
|---|
staticinlineonCut(cut:() ‑> String):Void
Registers a cut handler.
Parameters:
cut | Called when the platform requests cut text. |
|---|
staticinlineonCutCopyPaste(cut:() ‑> String, copy:() ‑> String, paste:String ‑> Void):Void
Registers cut, copy, and paste handlers at once.
This is the low-level clipboard registration point used by the convenience helpers above.
Parameters:
cut | Called when cut text is requested. |
|---|---|
copy | Called when copy text is requested. |
paste | Called with pasted text. |
staticinlineonDropFiles(dropFiles:String ‑> Void):Void
Registers a file drop handler.
Use this when your application needs to accept files from the desktop.
Parameters:
dropFiles | Called for each dropped file path. |
|---|
staticinlineonPaste(paste:String ‑> Void):Void
Registers a paste handler.
Parameters:
paste | Called with pasted text. |
|---|
staticstart(options:SystemOptions, ?setup:Window ‑> Void, ?started:() ‑> Void, ?progress:Float ‑> Void, ?failed:ResourceError ‑> Void):Void
Starts the application.
This is the low-level bootstrap entry point used by the generated
@:app.* startup code. It creates the Kha system, initializes the first
window, loads default engine resources, compiles shaders, and only then
starts the frame loop.
Most applications should prefer configuring startup declaratively through class metadata instead of calling this manually.
The setup callback is the place to configure the initial
Window and build scenes attached to it when a custom bootstrap
is needed.
Parameters:
options | Kha system options used to create the application. |
|---|---|
setup | Called once for the primary window before rendering starts. |
started | Called after initialization finishes and frame delivery has been registered. |
progress | Called with loading progress in the |
failed | Called when resource loading fails. |