viewer

Controls the Codea viewer and exposes display mode, runtime, presentation, and screen layout state.

mode: enum

Changes the display mode of the viewer. Use this to render your games and simulations in fullscreen mode, fullscreen mode without buttons, or standard mode. Standard mode includes the sidebar with output and parameters, plus controls for project execution.

Syntax:
viewer.mode = STANDARD
viewer.mode = FULLSCREEN
viewer.mode = FULLSCREEN_NO_BUTTONS
framerate: number

Sets the preferred framerate of the viewer. You can set this to 0, 15, 30, 60 or 120. The value 0 uses the maximum framerate of your device.

Note that this sets the preferred framerate. If the framerate cannot be maintained, it may drop below your preferred setting to the next lower value.

Syntax:
viewer.framerate = 30
pointerLocked: boolean

Setting this property to true indicates the renderer’s preference to lock the pointer, although the system may not honor the request. For the system to consider locking the pointer, the viewer must be running fullscreen on your device.

Syntax:
viewer.pointerLocked = true
runtime: number [readonly]

The active runtime type, either LEGACY or MODERN.

Syntax:
if viewer.runtime == viewer.MODERN then
    style.strokeWidth(5)
end
safeArea: table

A table specifying the current safe area insets of the viewer. Use these values to avoid rendering important visible or interactive content under system interface areas.

Parameters:
  • top (number) – The top inset of the safe area.

  • left (number) – The left inset of the safe area.

  • bottom (number) – The bottom inset of the safe area.

  • right (number) – The right inset of the safe area.

Syntax:
print(viewer.safeArea.bottom)
uniformResizing: boolean

Controls whether the viewer preserves a uniform resizing behavior when the view changes size. This is only supported on platforms where the viewer is resizable.

viewer.resize(width, height)

Resizes the viewer to the specified width and height. This is only supported on platforms where the viewer is resizable.

Parameters:
  • width (number) – The new viewer width.

  • height (number) – The new viewer height.

Syntax:
viewer.resize(800, 600)
paused: boolean

A boolean value that indicates whether the viewer is paused.

displayStats: boolean

Controls whether runtime statistics are displayed in the viewer.

drawOnRequest: boolean

Controls whether the viewer draws only when a redraw is requested.

showWarnings: boolean

Determines whether warnings should be displayed in the viewer. For example, warnings will be printed when using deprecated Codea APIs.

viewer.close()

Closes the viewer and returns to the editor. Calling viewer.close() is functionally the same as pressing the on-screen Back button.

Syntax:
viewer.close()
viewer.restart()

Restarts the viewer, starting your project again. Calling viewer.restart() is functionally the same as pressing the on-screen Restart button.

Syntax:
viewer.restart()
viewer.snapshot()

Captures the rendered contents of the viewer and returns them as an image. This captures the rendered scene and does not include the sidebar UI.

Returns:

The rendered viewer contents.

Return type:

image

Syntax:
local img = viewer.snapshot()
viewer.alert(message[, title])

Shows a system alert. The message parameter specifies the message to display. The optional title parameter provides the title of the alert. If no title is specified, "Alert" is used.

Parameters:
  • message (string) – Message to display.

  • title (string) – Alert title.

Syntax:
viewer.alert("Hello World")
viewer.alert("Hello World", "Title")
viewer.share(data)

Shows a system share view for an image, string, or table of shareable items. This allows you to share content to a third-party service, save it to your device, or copy it to the pasteboard.

Parameters:

data (image | string | table) – Content to share.

Syntax:
viewer.share(viewer.snapshot())
isPresenting: boolean [readonly]

Returns whether the viewer is presenting an alert, share sheet, or another view that obscures the viewer.

Syntax:
if not viewer.isPresenting then
    viewer.alert("Ready")
end
STANDARD: const

Standard display mode. The output and parameters panes are visible, and the Back, Pause, Play and Reset buttons are shown.

FULLSCREEN: const

Fullscreen display mode. An exit fullscreen button remains visible.

FULLSCREEN_NO_BUTTONS: const

Fullscreen display mode with all buttons hidden. Use viewer.close() if your project needs an explicit way to leave the viewer.

LEGACY: const

Legacy runtime identifier.

MODERN: const

Modern runtime identifier.