Main engine class.
Takes an object full of optional settings as a parameter.

import { Engine } from 'noa-engine'
var noa = new Engine({
debug: false,
})

Note that the options object is also passed to noa's child modules (Rendering, Container, etc). See docs for each module for their options.

Hierarchy

Constructors

  • The core Engine constructor uses the following options:

    var defaultOptions = {
    debug: false,
    silent: false,
    playerHeight: 1.8,
    playerWidth: 0.6,
    playerStart: [0, 10, 0],
    playerAutoStep: false,
    playerShadowComponent: true,
    tickRate: 30, // ticks per second
    maxRenderRate: 0, // max FPS, 0 for uncapped
    blockTestDistance: 10,
    stickyPointerLock: true,
    dragCameraOutsidePointerLock: true,
    stickyFullscreen: false,
    skipDefaultHighlighting: false,
    originRebaseDistance: 25,
    }

    Events:

    • tick => (dt)
      Tick update, dt is (fixed) tick duration in ms
    • beforeRender => (dt)
      dt is the time (in ms) since the most recent tick
    • afterRender => (dt)
      dt is the time (in ms) since the most recent tick
    • targetBlockChanged => (blockInfo)
      Emitted each time the user's targeted world block changes
    • addingTerrainMesh => (mesh)
      Alerts client about a terrain mesh being added to the scene
    • removingTerrainMesh => (mesh)
      Alerts client before a terrain mesh is removed.

    Parameters

    • opts: {} = {}

      Returns Engine

    Properties

    blockTargetIdCheck: ((blockID) => boolean)

    Type declaration

      • (blockID): boolean
      • Callback to determine which voxels can be targeted. Defaults to a solidity check, but can be overridden with arbitrary logic.

        Parameters

        • blockID: number

        Returns boolean

    blockTestDistance: number

    How far to check for a solid voxel the player is currently looking at

    camera: Camera

    Manages the game's camera, view angle, sensitivity, etc.

    container: Container

    Child module for managing the game's container, canvas, etc.

    defaultBlockHighlightFunction: ((tgt) => void)

    Type declaration

      • (tgt): void
      • Parameters

        • tgt: any

        Returns void

    entities: Entities

    Entity manager / Entity Component System (ECS)

    ents: Entities

    Alias to noa.entities

    inputs: Inputs

    Manages key and mouse input bindings

    listenerCount: {
        (type): any;
        (emitter, type): any;
    }

    Type declaration

      • (type): any
      • Parameters

        • type: any

        Returns any

      • (emitter, type): any
      • Parameters

        • emitter: any
        • type: any

        Returns any

    maxRenderRate: number

    The game's max framerate (use 0 for uncapped)

    off: any
    on: any
    physics: Physics

    Physics engine - solves collisions, properties, etc.

    playerEntity: number

    Entity id for the player entity

    registry: Registry

    A registry where voxel/material properties are managed

    rendering: Rendering

    Rendering manager

    targetedBlock: {
        adjacent: number[];
        blockID: number;
        normal: number[];
        position: number[];
    }

    Dynamically updated object describing the currently targeted block.

    Type declaration

    • adjacent: number[]
    • blockID: number
    • normal: number[]
    • position: number[]
    tickRate: number

    The game's tick rate (number of ticks per second)

    timeScale: number

    Multiplier for how fast time moves. Setting this to a value other than 1 will make the game speed up or slow down. This can significantly affect how core systems behave (particularly physics!).

    version: string

    Version string, e.g. "0.25.4"

    world: World

    Manages the world, chunks, and all voxel data

    worldName: string

    String identifier for the current world. It's safe to ignore this if your game has only one level/world.

    Methods

    • Adds a block, unless there's an entity in the way.

      Parameters

      • id: any
      • x: any
      • y: number = 0
      • z: number = 0

      Returns any

    • Parameters

      • type: any
      • listener: any

      Returns any

    • Parameters

      • type: any
      • Rest ...args: any[]

      Returns boolean

    • Get the voxel ID at the specified position

      Parameters

      • x: any
      • y: number = 0
      • z: number = 0

      Returns any

    • Precisely converts a world position to the current internal local frame of reference.

      See /docs/positions.md for more info.

      Params:

      • global: input position in global coords
      • globalPrecise: (optional) sub-voxel offset to the global position
      • local: output array which will receive the result

      Parameters

      • global: any
      • globalPrecise: any
      • local: any

      Returns any

    • Precisely converts a world position to the current internal local frame of reference.

      See /docs/positions.md for more info.

      Params:

      • local: input array of local coords
      • global: output array which receives the result
      • globalPrecise: (optional) sub-voxel offset to the output global position

      If both output arrays are passed in, global will get int values and globalPrecise will get fractional parts. If only one array is passed in, global will get the whole output position.

      Parameters

      • local: any
      • global: any
      • globalPrecise: any = null

      Returns any

    • Raycast through the world, returning a result object for any non-air block

      See /docs/positions.md for info on working with precise positions.

      Parameters

      • pos: number[] = null

        where to pick from (default: player's eye pos)

      • dir: number[] = null

        direction to pick along (default: camera vector)

      • dist: number = -1

        pick distance (default: noa.blockTestDistance)

      • blockTestFunction: ((id) => boolean) = null

        which voxel IDs can be picked (default: any solid voxel)

          • (id): boolean
          • Parameters

            • id: number

            Returns boolean

      Returns {
          _localPosition: number[];
          normal: number[];
          position: number[];
      }

      • _localPosition: number[]
      • normal: number[]
      • position: number[]
    • Sets the voxel ID at the specified position. Does not check whether any entities are in the way!

      Parameters

      • id: any
      • x: any
      • y: number = 0
      • z: number = 0

      Returns void

    • Pausing the engine will also stop render/tick events, etc.

      Parameters

      • paused: boolean = false

      Returns void

    Generated using TypeDoc