Skip to content

Scene Management

UnbelievableFlavour edited this page Jun 9, 2022 · 1 revision

Cotton comes with an integrated scene switching library. This makes it possible to completely switch out of your current level/game, do something else like show a cutscene, and then come back! The default scene is loaded in main.lua with the scene.set function.

Scene Management Functions

push

You can add additional scenes by calling:

scene.push(sceneObject)

pushOverlay

You can add additional scenes by calling:

scene.pushOverlay(sceneObject)

back

You can go back to the previous scene like so:

scene.back()

backTo

To go back to a specific scene, call:

scene.backTo(sceneObject)

isInStack

To check if a scene is in the scene stack.

scene.isInStack(sceneObject)

Scene Object Functions

The scene object is the object that you give to the scene manager. Example of the most simple scene object:

local exampleScene = {}

init

function exampleScene.init()
    -- log("I'm initialised!")
end

This function is called on initialisation.

resume

function exampleScene.resume()
    -- log("I'm resuming!")
end

This function is called when switching between scenes or resetting.

update

function exampleScene.update()
    -- log("I'm updating")
end

This function is called in update loop.

shutdown

function exampleScene.shutdown()
    -- log("I'm shutting down")
end

This function is called on scene switching.