Manual

Changing Scenes

Use this guide when you want to move the player from one screen or level to another.

Examples:

  • main menu -> level 1
  • level 1 -> level 2
  • game over -> retry screen

The Smallest Working Example

You can change scenes from gameplay code with the helper function:

loadScene('Level 02');

You can also load by index:

loadScene(1);

Step 1: Add A Trigger Behaviour

Attach a behaviour to a door, portal, or exit object.

<?php

namespace MyGame\Scripts\Transitions;

use Sendama\Engine\Core\Behaviours\Behaviour;
use Sendama\Engine\Physics\Interfaces\CollisionInterface;

final class ExitDoor extends Behaviour
{
    public function onTriggerEnter(CollisionInterface $other): void
    {
        if ($other->getGameObject()->hasTag('player')) {
            loadScene('Level 02');
        }
    }
}

Step 2: Make Sure The Scene Name Matches

When you use a string, it must match the scene name exactly.

If you prefer index-based flow, keep a list and call loadScene($nextIndex).

Step 3: Test The Transition

  1. run the game
  2. move the player into the trigger
  3. verify the new scene loads

If nothing changes, check:

  • the trigger callback is running
  • the colliding object has the player tag
  • the scene name is correct

Other Useful Runtime Helpers

  • loadPreviousScene() - go back to the previous scene
  • prompt(string $message) - ask for text input in terminal flow
  • quitGame() - stop the game loop

Related Guides