Skip to content
Mizu edited this page Aug 1, 2023 · 2 revisions

scenes are a core concept of novum. a game should be composed of multiple scenes (for example, the mandatory initial scene, a scene for the level selection, a scene that handles the gameplay...).

novum functions

novum:switchSceneInstant(name)

switches to the specified scene instantly

novum:switchSceneByTransition(name, transition, duration)

switches to the specified scene instantly

novum:discoverScene(name)

creates a new scene with the specified name. there should be a file in scenes/name.lua where name is the specified name.

novum automatically discovers the initial scene (scenes/initial.lua) and switches to it when the game starts.

auto-discovery

novum lets you discover scenes automatically using novum:discoverAll Scenes. it will find everything in the game's scenes folder and import every lua file that doesn't start with _.

defining a scene

here's how a scene file should be structured:

local Scene = {
    -- data
    foo = 'bar',
    spam = 'eggs',
    one = function(self) return 1 end,

    -- callbacks
    update = function(self, game, dt) ... end,
    draw = function(self, game) ... end,
}

return Scene

you may also do:

local Scene = {}

-- data
Scene.foo = 'bar'
Scene.spam = 'eggs'
function Scene:one()
    return 1
end

-- callbacks
function Scene:update(game, dt) ... end
function Scene:draw(game) ... end

return Scene

implemented callbacks

novum has implemented the following LÖVE callbacks (note: game is the novum framework):

  • scene:load(game)
  • scene:update(game, dt)
  • scene:draw(game)
  • scene:keypressed(game, key)
  • scene:keyreleased(game, key)
  • scene:touchpressed(game, id, x, y, dx, dy, pressure)
  • scene:touchmoved(game, id, x, y, dx, dy, pressure)
  • scene:touchreleased(game, id, x, y, dx, dy, pressure)

in addition, novum has custom callbacks:

  • scene:opened(game, data) is called as soon as a scene is switched to (after any possible transitions finish).