Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Time

Manages script execution and engine time.

Time methods and properties allow you to

  • Set up functions that are called every frame or in repeating intervals
  • Delay script execution
  • Get time data

Index

Variables

currentTime: number
returns

time (in seconds) that passed since start.

Functions

  • schedule(func: (() => void), delay: number): Disposable
  • Executes a function after a delay.

    Parameters

    • func: (() => void)

      function to execute after delay.

        • (): void
        • Returns void

    • delay: number

      delay in seconds.

    Returns Disposable

  • scheduleRepeating(func: ((deltaTime: number) => void), period: number): Disposable
  • scheduleRepeating(func: ((deltaTime: number) => void)): Disposable
  • Repeats execution of a function every period.

    Example

    const myEllipsoid = Scene.createEllipsoid(0, 0, 0)
    Time.scheduleRepeating(() => {
    myEllipsoid.speech = `${Time.currentTime.toFixed(2)} seconds have passed.`
    }, 1)

    Parameters

    • func: ((deltaTime: number) => void)

      function to execute repeatedly.

        • (deltaTime: number): void
        • Parameters

          • deltaTime: number

          Returns void

    • period: number

      period in seconds. Default is 0, causing script to be repeated every frame.

    Returns Disposable

  • Repeats execution of a function every frame.

    Example

    //Creates an ellipsoid which says the time that passed since start every frame
    const myEllipsoid = Scene.createEllipsoid(0, 0, 0)
    Time.scheduleRepeating(() => {
    myEllipsoid.speech = `${Time.currentTime.toFixed(2)} seconds have passed.`
    })

    //Creates a cuboid which moves at a constant speed independent of device performance
    const myCuboid = Scene.createCuboid(0, 0, 0)
    let speed = 0.1
    Time.scheduleRepeating(deltaTime => {
    let currentPosition = myCuboid.transform.position
    myCuboid.transform.position = currentPosition.add(Vector3.axisX.mult(speed * deltaTime))
    })

    Parameters

    • func: ((deltaTime: number) => void)

      function to execute every frame.

        • (deltaTime: number): void
        • Parameters

          • deltaTime: number

          Returns void

    Returns Disposable