Construct 2 has been officially retired. Now you should upgrade to Construct 3.
Runtime reference
The runtime object represents a single instance of a user's project running in the browser. It is usually accessed via this.runtime from an object instance. Remember only documented properties and methods should be used.
Runtime properties
- runtime.canvas (read-only)
- The canvas element in the page the project is running on.
- runtime.width (read-only)
- runtime.height (read-only)
- The size of the canvas element in the page. This can change at runtime if Fullscreen in browser is enabled and the user resizes the browser window.
- runtime.redraw (write-only)
- This must be set to true whenever anything is done that affects how the project is rendered. If redraw remains false, the canvas is assumed not to have changed and will not be redrawn.
- runtime.plugins[]
- An array of all the plugins used in the project.
- runtime.types_by_index[]
- An array of all the object types in the project.
- runtime.layouts_by_index[]
- An array of all the layouts in the project.
- runtime.eventsheets_by_index[]
- An array of all the event sheets in the project.
- runtime.wait_for_textures[] (write-only)
- Add a HTML Image() class to this array during loading, and the loader will wait for it to finish downloading before starting the runtime. See Tiled Background for an example.
- runtime.timescale
- The current time scale.
- runtime.kahanTime.sum (read-only)
- The current in-game time, in seconds, with timescaling applied.
- runtime.tickcount
- The number of ticks elapsed since the start of the game.
- runtime.changelayout (write-only)
- Set to a reference to a layout object and the following tick the runtime will execute Go to layout on that layout.
- runtime.running_layout (read-only)
- A reference to the current layout that is running.
- runtime.files_subfolder (read-only)
- The subfolder where project files are held.
- runtime.extra
- The runtime is sealed. You may store any additional properties you need in this object.
- runtime.start_time (read-only)
- Set to date.getTime() on starting the first layout.
Runtime functions
- runtime.tickMe(this)
- Call to have the runtime call tick() on your plugin instance. You must define a tick() method in the instance's prototype. Note: behaviors are automatically ticked.
- runtime.getDt(this)
- Return delta-time, in seconds, with time scaling applied. You must pass an instance to get dt for, to maintain compatibility with the Set object timescale feature.
- runtime.addDestroyCallback(f)
- Calls f(inst) whenever an instance is destroyed.
- runtime.DestroyInstance(inst)
- Destroys the given instance.
- runtime.createInstance(type, layer)
- Create a new instance of the object type on the given layer. Returns a reference to the created instance.
- runtime.getLayerByName(name)
- Get a layer by name, case insensitive, or null if not found.
- runtime.getLayerByNumber(index)
- Get a layer by zero-based index, or null if out of bounds.
- runtime.testAndSelectCanvasPointOverlap(type, x, y, inverted)
- Pick any instances of type that overlap the point (x, y) in canvas co-ordinates. Pass the condition's inverted state for correct behavior. See the Mouse object for an example.
- runtime.testOverlap(a, b)
- Return true if the two given instances are overlapping.
- runtime.testOverlapSolid(inst)
- Returns an instance with the Solid attribute if inst is overlapping a solid, else null.
- runtime.pushOutSolid(inst, xdir, ydir, dist)
- Pushes inst the distance given by xdir and ydir up to dist, until inst is not overlapping any solid. If inst finishes overlapping a solid, it is put back to its original position and false is returned. Otherwise, true is returned.
- runtime.pushOutSolidNearest(inst, max_dist)
- Pushes inst in an 8-direction spiral pattern up to max_dist pixels away until it is no longer overlapping a solid. If inst is still overlapping a solid by max_dist, it is returned to its original position and false is returned. Otherwise, true is returned.
- runtime.trigger(method, inst)
- Trigger the condition specified by method, with the object inst triggering. The condition must specify cf_trigger and not cf_faketrigger. If triggering your own plugin's trigger, pass this for inst. method must specify the plugin routine in the form:
cr.plugins_.MyPluginID.prototype.cnds.MyTrigger
e.g.:
cr.plugins_.Mouse.prototype.cnds.OnClick
- runtime.getCurrentCondition()
- Returns the current condition. Only valid in condition methods.
- runtime.getCurrentAction()
- Returns the current action. Only valid in action methods.
- runtime.getCurrentEventStack()
- Return the current event "stack frame". This can be used to determine the current event via runtime.getCurrentEventStack().current_event.
Construct 2 Javascript SDK Manual
Construct.net
2020-06-04
2020-06-05
You are here:
Search this manual:
This manual entry was last updated on 5 Jun, 2020 at 11:56