9. Scene Management

9.1. Scene Properties

Scenes are divided into layers and contain the different elements that make up a game.

Scene property

Scenes, like entities, have their own properties:

  • World’s Width – The width of the scene in pixels
  • World’s Height – The height of the scene in pixels
  • Aspect Ratio – The ratio of the scene’s size to the device’s screen
  • Scaling Method – Either the scene has No Scaling or it’s set to Fit in Viewport
  • Scale – The pixel-to-meter ratio of physics on the scene
  • Gravity x & y – The amount of gravity(in the form of a vector) on the x and y axis for the scene
  • Allow Sleep – Specifies whether or not physics objects can sleep
  • Collision Outlines – Sets the physics’ bounding-box to be visible or hidden
  • Layers – The maximum number of layers on the scene
  • Default Entity Layer – The layer that entities are placed by default, this layer is set update automatically

Scene Parameters

Scene Parameters have a value(number, string, boolean) that can be set or returned. Here’s a list of the different scene parameters:

  • Id – Used to return the scene’s Id
  • Gravity x & y – Used to set or return the amount of gravity on the x and y axis for the scene
  • Width & Height – Used to set or return the height or width of the scene
  • Scale – Used to set or return the pixel-to-meter ratio of physics on the scene
  • Allow Sleep – Specifies whether or not physics objects can sleep
  • Collision Outlines – Sets the physics’ bounding-box to be visible or hidden
  • Scaling Method – Sets the scaling method to either “Fit in viewport” or “no scaling”
  • Camera x & y – Used to set or return the x and y position of the camera on the scene

9.2. Getting Scene Properties

You can return the value of an scene parameter using the Scene Property Command.

Scene parameter

The returned value from the scene parameter can be stored in a variable, used in a mathematical operation, etc.

Get scene

9.3. Setting Scene Properties

The values in scene parameters can be set or changed while the game is running. You use the same Scene Property Command, you just set a value instead of returning it. Parameters can be set the same way as variables however, there are some restrictions.

  • Id and Scaling Method can only be set to a string value
  • Gravity x, Gravity y, Width, Height, Scale, Camera x and Camera y can only be set to a number
  • Allow Sleep and Collision Outlines can only be set to boolean, 1(true) or 0(false)

Here’s a way you could set scene parameters:

Set camera

By setting the Camera X & Y parameters to the entity’s Top & Left, the entity will always remain in the viewport.

9.4. Switching Between Scenes

For games with more than one scene, you use the Switch Scene Command to move to any other scene.

Switch scene

When the Switch Scene Command is executed, an instance of the other scene is created and the current scene is destroyed. Each time you move to a scene its entities execute their create events.