Overview

VOLTS provides you with a helper class that can manage events, snapshot signals, update SceneObjects, and do many more things!

World.getInstance

The getInstance function returns the current instance, or creates a new instance if none has been created before

import { World } from './volts';

// this'd throw an error, as it needs some parameters the first time
// World.getInstance();

const Instance = World.getInstance({
  mode: 'PRODUCTION',
});

// now you can getIntance() without parameters
// to get access to the one and only instance
Instance === World.getInstance(); // true

If you are calling getInstance for the first time, meaning you intend to create a new instance, you need to supply some parameters. After the first instance has been created, you can call getInstance without any parameters

Parameters:

  • mode: This parameter is required. It represents which 'mode' or behavior you want your code to follow, there are 3 modes to choose from. It's recommended that DEV is used while developing and iterating, and later switched to PRODUCTION once you want to export/push to a device.

    • DEV: this mode has some additional checks and procedures, which are used to make Volts play nicer (around its bugs) with Spark AR Studio

    • PRODUCTION: this mode just runs your code as it is, no additional checks or workarounds, which don't matter on device

    • NO_AUTO: this mode is more advanced and is only recommended for scripts which try to extend the VoltsWorld class

  • assets: This parameter is optional. An object composed of key-value pairs, with the values being a Promise that resolves to some asseet in Spark AR Studio

  • snapshot: This parameter is optional. An object composed of key-value pairs, with the values being a Signal of type ScalarSignal, Vec2Signal, VectorSignal, Vec4Signal, StringSignal, or BoolSignal. Which get snapshot-ed to number, Vector, string, and boolean (s)

  • loadStates: a State (or array of States) which are to be loaded by the time the World has loaded

Example using all parameters:

Last updated

Was this helpful?