Screen

backend.Screen (Class)
Implements: tracker.Events

Clay backend screen and window management implementation.

This class handles screen-related operations including:

  • Window dimensions and display properties
  • Window title and fullscreen state management
  • Screenshot capture functionality (texture, PNG, raw pixels)
  • Mouse and touch input event handling
  • Audio context resumption on web platforms

Platform-specific features:

  • Web: HTML5 Canvas and Electron integration for fullscreen
  • Desktop (SDL): Direct OpenGL framebuffer reading for screenshots
  • Mobile: Touch input event handling and audio context management

Instance Members

clay
getWidth(): Int

Gets the current screen width in pixels.

Returns Description
Int Screen width in pixels

clay
getHeight(): Int

Gets the current screen height in pixels.

Returns Description
Int Screen height in pixels

clay
getDensity(): Float

Gets the current screen pixel density/scale factor.

Returns Description
Float Pixel density (1.0 = standard, 2.0 = retina/high-DPI, etc.)

clay
setBackground(background: Int): Void

Sets the window background color.

Note: This method is currently unused as background clearing is handled directly in the draw loop.

Name Type Description
background Int Background color as integer

clay
setWindowTitle(title: String): Void

Sets the window title text.

Name Type Description
title String New window title

clay
setWindowFullscreen(fullscreen: Bool): Void

Sets the window fullscreen state.

On web platforms, this checks for Electron runner integration and uses native fullscreen if available, otherwise falls back to HTML5 fullscreen API.

Name Type Description
fullscreen Bool True to enable fullscreen, false to disable

clay
screenshotToTexture(done: Function): Void
Name Type
done Function

clay
screenshotToPng(?path: String, done: Function): Void
Name Type Default
path String (optional)
done Function

clay
screenshotToPixels(done: Function): Void
Name Type
done Function

clay
unbindEvents(): Void

clay
new(): Void

Creates a new Screen backend instance.

Private Members

clay
nextScreenshotIndex: Int

Index counter for generating unique screenshot identifiers.


clay
emitResize(): Void

Fired when the screen/window is resized.


clay
emitMouseDown(buttonId: Int, x: Float, y: Float): Void

Fired when a mouse button is pressed down.

Name Type Description
buttonId Int Mouse button ID (0=left, 1=middle, 2=right)
x Float Mouse X coordinate
y Float Mouse Y coordinate

clay
emitMouseUp(buttonId: Int, x: Float, y: Float): Void

Fired when a mouse button is released.

Name Type Description
buttonId Int Mouse button ID (0=left, 1=middle, 2=right)
x Float Mouse X coordinate
y Float Mouse Y coordinate

clay
emitMouseWheel(x: Float, y: Float): Void

Fired when the mouse wheel is scrolled.

Name Type Description
x Float Horizontal scroll amount
y Float Vertical scroll amount

clay
emitMouseMove(x: Float, y: Float): Void

Fired when the mouse cursor moves.

Name Type Description
x Float Mouse X coordinate
y Float Mouse Y coordinate

clay
emitTouchDown(touchIndex: Int, x: Float, y: Float): Void

Fired when a touch begins on the screen.

Name Type Description
touchIndex Int Touch point index for multi-touch
x Float Touch X coordinate
y Float Touch Y coordinate

clay
emitTouchUp(touchIndex: Int, x: Float, y: Float): Void

Fired when a touch ends.

Name Type Description
touchIndex Int Touch point index for multi-touch
x Float Touch X coordinate
y Float Touch Y coordinate

clay
emitTouchMove(touchIndex: Int, x: Float, y: Float): Void

Fired when a touch point moves.

Name Type Description
touchIndex Int Touch point index for multi-touch
x Float Touch X coordinate
y Float Touch Y coordinate

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()