q5play
    Preparing search index...

    Class Camera

    The Camera controls the position and zoom of the view of the world that is drawn on the canvas.

    Index
    isActive: boolean

    Read only. True if the camera is active. Use camera.on() to activate the camera.

    false
    
    • get pos(): { x: number; y: number }

      Gets the camera's position as a readonly {x, y} object that won't be updated if the camera moves. Useful for saving the camera's position at a specific moment in time.

      Returns { x: number; y: number }

    • set pos(val: number[] | { x: number; y: number }): void

      The camera's position.

      Parameters

      • val: number[] | { x: number; y: number }

      Returns void

    • get zoom(): number

      Camera zoom.

      A scale of 1 will be the normal size. Setting it to 2 will make everything appear twice as big. .5 will make everything look half size.

      Returns number

      1
      
    • set zoom(val: number): void

      Parameters

      • val: number

      Returns void

    • Moves the camera to a position.

      Parameters

      • x: number
      • y: number
      • speed: number

      Returns Promise<boolean>

      resolves true when the camera reaches the target position

    • Deactivates the camera.

      The canvas will be drawn normally, ignoring the camera's position and scale until camera.on() is called.

      Returns void

    • Activates the camera.

      The canvas will be drawn according to the camera position and scale until camera.off() is called.

      Returns void

    • Zoom the camera at a given speed.

      Parameters

      • target: number

        The target zoom

      • speed: number

        The amount of zoom per frame

      Returns Promise<boolean>

      resolves true when the camera reaches the target zoom