rapid-render
    Preparing search index...

    Class Game

    Main game class managing the game loop, rendering, and input.

    Index

    Constructors

    Properties

    asset: AssetsLoader
    audio: AudioManager
    mainScene: null | Scene = null
    render: Rapid
    renderQueue: Entity[] = []
    texture: TextureCache

    Methods

    • Adds an entity to the render queue.

      Parameters

      • entity: Entity

        The entity to add.

      Returns void

    • Creates and starts a new timer that will be automatically updated by the game loop.

      Parameters

      • duration: number

        The duration in seconds before the timer triggers.

      • repeat: boolean = false

        If true, the timer will restart after completing. Defaults to false.

      Returns Timer

      The created Timer instance, allowing you to stop() it manually if needed.

      // Log a message after 2.5 seconds
      game.createTimer(2.5, () => {
      console.log('Timer finished!');
      });

      // Spawn an enemy every 5 seconds
      const enemySpawner = game.createTimer(5, () => {
      scene.spawnEnemy();
      }, true);
    • Creates and starts a new tween animation. The tween will be automatically updated by the game loop.

      Type Parameters

      • T extends number | IMathObject<T>

        The type of the value being animated (e.g., Vec2, Color, number).

      Parameters

      • target: any

        The object to animate.

      • property: string

        The name of the property on the target to animate.

      • to: T

        The final value of the property.

      • duration: number

        The duration of the animation in seconds.

      • easing: EasingFunction = Easing.Linear

        The easing function to use. Defaults to Linear.

      Returns Tween<T>

      The created Tween instance, allowing you to chain calls like .onComplete().

      // Tween a sprite's position over 2 seconds
      game.createTween(mySprite, 'position', new Vec2(500, 300), 2, Easing.EaseOutQuad);

      // Tween a shape's color to red and do something on completion
      game.createTween(myShape, 'color', Color.Red, 1.5)
      .onComplete(() => {
      console.log('Color tween finished!');
      });
    • Starts the game loop.

      Returns void

    • Stops the game loop.

      Returns void

    • Switches to a new scene, disposing of the current one.

      Parameters

      • newScene: Scene

        The new scene to switch to.

      Returns void