GameObjectInterface

Namespace:

namespace Lenga\Engine\Interfaces;

Defines the standard contract for a Lenga game object. All scene objects implement this interface, which provides a consistent API for activation, hierarchy traversal, and component management. Type-hinting against GameObjectInterface lets you write code that works with any game object without depending on the concrete GameObject class.

Methods

setActive / isActiveSelf / isActiveInHierarchy

public function setActive(bool $value): void
public function isActiveSelf(): bool
public function isActiveInHierarchy(): bool

Controls and queries the active state of the object. isActiveSelf reflects the local flag; isActiveInHierarchy accounts for parent state.

getScene / getParent / getChildren / childCount

public function getScene(): mixed
public function getParent(): ?static
public function getChildren(): array
public function childCount(): int
public function setParent(?self $parent, bool $worldPositionStays = true): void

Hierarchy traversal and parenting methods.

hasComponent / getComponent / addComponent / destroy

public function hasComponent(string $type): bool
public function getComponent(string $type): mixed
public function addComponent(string $type): mixed
public function destroy(): void

Component management methods, mirroring the GameObject API.

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Interfaces\GameObjectInterface;

/**
 * Recursively activates an object and all of its children.
 */
function activateTree(GameObjectInterface $obj): void
{
    $obj->setActive(true);
    foreach ($obj->getChildren() as $child) {
        activateTree($child);
    }
}

class SceneBootstrapper extends Behaviour
{
    public function start(): void
    {
        activateTree($this->gameObject);
    }
}