Runtime class controls execution of a project. It is the equivalent of an IProject at runtime.
The following events are fired on the runtime dispatcher, which is accessed using
runtime.Dispatcher(). For example to add an "instancedestroy" event, use
- Fired when any instance is destroyed. The callback receives an event object with an
instance property referring to the Instance that was destroyed. Use this event to ensure all references to destroyed instances are dropped.
- Fired after the
LoadFromJson call after the rest of the runtime has finished loading. This means all objects are available and can be looked up by their UID. For example to save a reference to an instance, save its UID to JSON, load its UID and store it in
LoadFromJson(), and then look it up with
GetInstanceByUID() in the "afterload" event.
- Return the runtime event dispatcher. This is where runtime events are fired. For example use
runtime.Dispatcher().addEventListener(...) to listen for a runtime event.
- Return the project's AssetManager, which is used to load sub-resources.
- Only valid while the project is still loading. Add a promise that the runtime will wait to resolve before starting the first layout. This is useful if you want to make sure your addon loads a dynamic resource before the game starts.
- Return true if the runtime is hosted in a worker. The DOM will be unavailable.
- Returns true if running in Construct 3's preview mode.
- Return a read-only array of all ObjectClass in the project. Note this includes families.
- Look up an ObjectClass by a case-insensitive string of its name. Note this can return a family.
- Look up an ObjectClass by a SID (Serialization ID), which is a unique number assigned to every ObjectClass. Note this can return a family.
- Look up a single-global plugin's ObjectClass by its plugin constructor function, e.g.
null if the plugin is not added to the project.
- CreateInstance(objectClass, layer, x, y)
- Create and return a new Instance of an ObjectClass on the given Layer at a position.
- Destroy an Instance.
- Get the total number of instances created.
- Look up an Instance by its UID. If none exists with the given UID, returns
- Return the EventSheetManager that handles the event system.
- Return the EventStack. This is a shorthand for
- Return the current EventStackFrame. This is a shorthand for
- Return the current EventBlock. This is a shorthand for
- Return the offset of the canvas in the document in CSS pixels.
- Return the size of the canvas in the document in CSS pixels.
- Return one of
"trilinear", reflecting the project Sampling property.
- Call to indicate that something visible has changed. Most runtime code calls this automatically. However by default if this is not called during a tick, the runtime will skip drawing a frame on the assumption nothing visible has changed.
- Return the WebGLRenderer for the runtime, which is responsible for rendering graphics.
- Return the main Layout that is currently running.
- Set and get the timescale as a multiplier.
- Get the current delta-time (time the last frame took) in seconds. You can optionally pass an Instance to get delta-time using the object's own timescale.
- Get the timestamp in milliseconds at the time the runtime started up.
- Get the in-game time in seconds, which can be affected by time scaling.
- Get the in-game time in seconds without taking in to account time scaling (aka the "wall clock" time).
- Get the number of ticks that have elapsed so far.
- Return a string of the name and version of the project.
- Return a string representing a unique identifier for this project.
- Set and get a boolean indicating whether pixel rounding is enabled.
- InvokeDownload(url, filename)
- Invoke a download of the given URL and use the provided filename. The URL can be a blob URL.
- Generate a random number in the range [0,1), which is the same range as
Math.random(). Use this method to allow the runtime control over the random number generator, e.g. setting a fixed seed to reproduce the same random sequence.
true to suspend the runtime or
false to resume it if paused. When suspended, the entire runtime halts and stops processing events or drawing the screen. This is done by default when the window or app goes in to the background.
Addon SDK Manual
You are here:
Search this manual:
This manual entry was last updated on 12 Aug, 2019 at 10:51