In order to simplify and improve developer experience, functions have been added to allow manipulation of the game world by developers.
API functions are divided into three, each differ in their usage.
node: used to manipulate objects (e.g. mass)
game: used to manipulate the game world (e.g. play sounds)
mesh: Returns properties of the parent mesh
API functions tend to require uuids of the target objects to run, which can be found on the properties window on the right side of the screen.
Used to manipulate object color.
Example: node.setColor("ZYG06", "#F54927")
Used to manipulate object position.
Example: node.setPosition("ZYG06", 0, 2, 0)
Used to manipulate object size.
Example: node.setSize("ZYG06", 2, 2, 2)
Used to manipulate object rotation.
Example: node.setRotation("ZYG06", 0, 3.14, 0)
Used to manipulate object mass.
Example: node.setMass("ZYG06", 1)
Used to add a text element to the game menu.
id - unique identification key for accessing the element.
Example: game.setMenu("points", `Your Points: ${x}`)
Used to send a local message (only applies to client).
Example: game.sendLocalMessage("3.14 is a funny number")
Used to play an audio track.
Example: game.playAudio("https://example.com/audio.mp3")
game.spawnMesh(type: String, sizeX: Number, sizeY: Number, sizeZ: Number, x: Number, y: Number, z: Number, mass: Number)
Spawns an object and returns its ID.
type - Type of mesh (refer to elemTypes in addShapes.js for mesh types)
Example: game.spawnMesh("cube", 1, 1, 1, 0, 2, 0, 0)
Deletes an object.
Example: game.deleteMesh("ZYG06")
Listens to a mesh for an event. Only runs callback once.
type - Only click for now
Example: game.createListener("ZYG06", "click", () => { console.log("boom"); })
Returns the parent mesh UUID
Returns the parent mesh position
Returns the parent mesh mass
Returns the parent mesh color
Returns the parent mesh size
Returns the parent mesh rotation