scene

class scene

A high level scene structure used that integrates object hierarchy, rendering, input, physics and serialisation to simplify and streamline games and simulations

main: scene

Sets the main Codea scene, which will be automatically drawn, updated and handle touch events

function setup()
   scene.main = scene.default3d()
end
static default3d()

Creates the default 3D scene containing a perspective camera, directional light and HDR environment

Return type:

scene

static default2d()

Creates the default 2D scene containing an orthographic camera

Return type:

scene

static read(key)

Loads and returns a scene with the supplied asset key

Return type:

scene

static save(key, scene)

Saves the supplied scene at the given asset key location

world2d: physics2d.world

Gets the scene’s 2D physics world, providing access to various physics functions and properties such as physics2d.world.applyForce()

world3d: physics3d.world

Gets the scene’s 3D physics world, providing access to various physics functions and properties such as physics3d.world.applyForce()

sky: None

Sets the sky visuals, which will depend on the type used:

  • asset.key - Use an image pointed to by a given asset key

  • image - Use an image directly (assumed to be a cube image)

  • color - Use a solid color

camera: entity
Returns:

The scene’s camera entity (if it exists)

Return type:

entity

sun: entity
Returns:

The scene’s sun entity (if it exists)

Return type:

entity

entity([name])

Creates a new blank entity with an optional name

Return type:

entity

findEntity(name)
Return type:

entity

entities([activeOnly = true])

Returns a table containing all root entities

Parameters:

activeOnly – When set, returns only active root entities

Return type:

table

index(name) [metamethod]

Returns the root entity with the given name (if it exists)

Return type:

entity

draw()

Immediately draws the scene to the current context. When autoUpdate is enabled, update(dt) will be called as well

If set as scene.main this will be called automatically right before the global draw() function

update(deltaTime)

Updates the scene, called automatically when draw() is called but can also be called manutally if needed