BackdropLayer

Namespace:

namespace Lenga\Engine\SceneManagement;

class BackdropLayer

BackdropLayer gives scripts live access to a scene backdrop layer.

Use it when you want to:

  • scroll a repeating background over time
  • slow the backdrop when the player reverses
  • speed it up during boost or warp effects
  • tune repeat, parallax, or offset at runtime

Properties

index

public int $index

The zero-based layer index in the active scene.

imagePath

public string $imagePath

The image assigned to this backdrop layer.

space

public string $space

The layer space, such as Screen or World.

depthPreset

public string $depthPreset

The current depth preset label for the layer.

offset

public Vector2 $offset

Reads or writes the layer offset.

Increasing offset.x makes a screen-space backdrop move left across the screen, which is useful for side-scrolling starfields and endless-runner backgrounds.

repeat

public Vector2 $repeat

Reads or writes the repeat flags as a vector.

In practice, use 1 to enable wrapping on an axis and 0 to disable it.

parallax

public Vector2 $parallax

Reads or writes the layer parallax strength.

Methods

fromNativeData

public static function fromNativeData(array $data): self

translateOffset

public function translateOffset(Vector2 $delta): bool

Adds a delta to the current offset.

This is the easiest way to animate a repeating backdrop each frame.

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Time;
use Lenga\Engine\Core\Vector2;
use Lenga\Engine\SceneManagement\SceneManager;

final class StarfieldController extends Behaviour
{
    public float $scrollSpeed = 40.0;

    public function update(): void
    {
        $scene = SceneManager::getActiveScene();
        $layer = $scene?->getBackdropLayer(0);
        if ($layer === null) {
            return;
        }

        $layer->repeat = new Vector2(1.0, 0.0);
        $layer->translateOffset(new Vector2(
            $this->scrollSpeed * Time::deltaTime(),
            0.0,
        ));
    }
}