Reference

Core Engine API

This page summarizes the runtime classes you will touch most often while building a game.

Engine Lifecycle At A Glance

flowchart TD
  A["Bootstrap game entry file"] --> B["Construct Game"]
  B --> C["loadScenes(...)"]
  C --> D["SceneManager loads scene metadata"]
  D --> E["GameObjects, components, and UI inflate"]
  E --> F["awake() and onStart() hooks"]
  F --> G["Main loop begins"]
  G --> H["Input polling"]
  H --> I["onUpdate() traversal"]
  I --> J["Fixed update and physics"]
  J --> K["Collision and trigger events"]
  K --> L["Renderer and UI draw frame"]
  L --> G
  G --> M["Scene change or stop"]
  M --> N["onStop() and cleanup"]

Minimal bootstrap example:

<?php

declare(strict_types=1);

use Sendama\Engine\Game;

require __DIR__ . '/vendor/autoload.php';

$game = new Game('Blasters');

$game
  ->loadScenes('Scenes/level01')
  ->loadSettings()
  ->run();

Sendama\Engine\Game

The main runtime entrypoint responsible for bootstrapping and running the game.

Typical responsibilities:

  • loading scenes
  • managing the game loop
  • coordinating rendering and runtime services

Projects usually construct or configure the game in their main entry file and then load scenes before starting play.

Typical scene bootstrap from a concrete scene class:

<?php

namespace Sendama\MyGame\Scenes;

use Sendama\Engine\Core\Scenes\AbstractScene;
use Sendama\Engine\Core\GameObject;

class Level01 extends AbstractScene
{
  public function __construct()
  {
    parent::__construct('Level 1');
  }

  public function awake(): void
  {
    $player = new GameObject('Player');
    $this->rootGameObjects[] = $player;
  }
}

Sendama\Engine\Core\GameObject

The primary runtime object type.

Key capabilities:

  • holds a Transform
  • holds a Renderer
  • can own additional components
  • can be active or inactive
  • can participate in scene hierarchy

Selected static methods:

Method Purpose
GameObject::instantiate(GameObject $original, ?Vector2 $position = null, ?Vector2 $rotation = null, ?Vector2 $scale = null, ?Transform $parent = null): GameObject Clone and add to the active scene
GameObject::destroy(GameObject $gameObject, float $delay = 0.0): void Remove object from scene
GameObject::pool(GameObjectInterface $gameObject, int $size): array Clone a template repeatedly
GameObject::find(string $name): ?GameObjectInterface Find first object by name in active scene hierarchy
GameObject::findWithTag(string $tag): ?GameObjectInterface Find first object by tag
GameObject::findAll(string $name): array Find all matching names
GameObject::findAllWithTag(string $tag): array Find all matching tags

Selected instance methods:

Method Purpose
addComponent(string $componentType): Component Attach a component
getTransform(): Transform Access transform
getRenderer(): Renderer Access renderer
getChildren(): array Read direct child objects
activate(): void Activate object
deactivate(): void Deactivate object
isActive(): bool Read active state
broadcast(string $methodName, array $args = []): void Call a method across components and children

Notes:

  • rendering, update, fixed update, start, stop, resume, and suspend all recurse through child objects
  • inactive objects are skipped by rendering and update traversal

Instantiation and pooling example:

<?php

use Sendama\Engine\Core\GameObject;
use Sendama\Engine\Core\Vector2;

$enemyTemplate = GameObject::find('Enemy Template');
$spawnPoint = Vector2::getClone($player->getTransform()->getPosition());

if ($enemyTemplate instanceof GameObject) {
  $enemy = GameObject::instantiate($enemyTemplate, position: $spawnPoint);
  $enemy->setTag('enemy');
}

$bulletPool = GameObject::pool($bulletTemplate, 32);

Sendama\Engine\Core\Transform

The position, rotation, scale, and parenting component.

Selected methods:

Method Purpose
getPosition(): Vector2 Get local position
setPosition(Vector2 $position): void Set local position
getWorldPosition(): Vector2 Get composed world position
setWorldPosition(Vector2 $position): void Set world position relative to parent
getRotation(): Vector2 Get local rotation
setRotation(Vector2 $rotation): void Set local rotation
getWorldRotation(): Vector2 Get composed world rotation
setWorldRotation(Vector2 $rotation): void Set world rotation relative to parent
getScale(): Vector2 Get scale
setScale(Vector2 $scale): void Set scale
translate(Vector2 $translation): void Move by offset
setParent(?Transform $parent, bool $preserveWorldTransform = false): void Reparent transform
getParent(): ?Transform Read parent
getChildren(): array Read child transforms

Parenting example:

<?php

use Sendama\Engine\Core\Vector2;

$weaponTransform = $weapon->getTransform();
$playerTransform = $player->getTransform();

$weaponTransform->setParent($playerTransform, preserveWorldTransform: true);
$weaponTransform->setPosition(new Vector2(x: 2, y: 0));

Sendama\Engine\Core\Vector2

The common 2D value type used across transforms, sprites, and gameplay data.

Typical uses:

  • positions
  • rotations
  • scales
  • motion vectors
  • renderer crop rectangles
  • serialized bounds

Common construction examples:

<?php

use Sendama\Engine\Core\Vector2;

$origin = new Vector2(x: 0, y: 0);
$velocity = new Vector2(x: 1, y: -1);
$bounds = new Vector2(x: 96, y: 32);

Sendama\Engine\Core\Rendering\Renderer

The rendering component attached to every GameObject.

Selected behaviors:

  • renders the object's sprite at its world position
  • captures and restores background underneath the sprite
  • uses the active scene world-space data as the rendering backdrop

Selected methods:

  • getSprite(): ?Sprite
  • setSprite(?Sprite $sprite): void
  • render(): void
  • renderAt(?int $x = null, ?int $y = null): void
  • erase(): void
  • eraseAt(?int $x = null, ?int $y = null): void

Renderer setup example:

<?php

use Sendama\Engine\Core\Rect;
use Sendama\Engine\Core\Sprite;
use Sendama\Engine\Core\Texture;
use Sendama\Engine\Core\Vector2;

$renderer = $gameObject->getRenderer();
$texture = new Texture('Textures/player.texture');
$sprite = new Sprite($texture, new Rect(new Vector2(0, 0), new Vector2(3, 1)));
$renderer->setSprite($sprite);
$renderer->render();

Sendama\Engine\Core\Scenes\AbstractScene

The base scene implementation backing concrete scenes.

Important responsibilities:

  • hold root game objects
  • hold UI elements
  • hold world-space environment data
  • expose scene width, height, and configured environment assets

Useful read surface:

  • getRootGameObjects(): array
  • getUIElements(): array

Typical scene query example:

<?php

use Sendama\Engine\Core\GameObject;

$player = GameObject::find('Player');
$hud = $scene->getUIElements();
$roots = $scene->getRootGameObjects();

Sendama\Engine\Core\Scenes\SceneManager

The runtime scene loading and metadata hydration service.

It is responsible for:

  • loading .scene.php files
  • inflating scene and prefab metadata into live objects
  • hydrating serialized component data
  • resolving prefab paths and asset-relative metadata

It also handles Vector2 hydration for typed fields and prefab hydration for GameObject-typed serialized properties.

Hydration-friendly serialized behaviour example:

<?php

return [
  'type' => Sendama\MyGame\Scripts\EnemySpawner::class,
  'data' => [
    'spawnRate' => 0.4,
    'maxEnemies' => 8,
    'spawnBounds' => ['x' => 96, 'y' => 24],
    'enemyPrefab' => 'Prefabs/enemy.prefab.php',
  ],
];