Construct 2 has been officially retired. Now you should upgrade to Construct 3.

The Edit-time

You cannot use browser features in the edit-time, since the edittime.js script is interpreted by Google's V8 javascript engine rather than a real browser. However, Construct 2 exposes some editor features in the edittime script. The functions and objects you can use are documented here.

Global functions

alert(msg)
Bring up a message box with the message. Generally only useful for testing or errors.
assert2(cnd, msg)
Assert that cnd is true, else cause a check failure with msg. This is only used in checked builds. However, it is useful for testing and diagnostics.
#Edittime callbacks#
CreateIDEObjectType()
Called whenever Construct 2 needs to create a new object type from your plugin.
IDEObjectType()
The class representing an object type in the editor.
IDEObjectType.CreateInstance()
Called whenever Construct 2 needs to create a new instance from your plugin.
IDEInstance()
The class representing an instance in the editor.
IDEInstance.OnInserted()
Called whenever the user manually inserts a new instance in to the project. Typically this is done via the Insert Object dialog.
IDEInstance.OnDoubleClicked()
Called when an instance is double-clicked in the layout. You may want to invoke the texture or animation editor here.
IDEInstance.OnPropertyChanged(name)
Called just after one of the plugin properties has been changed for this instance. For link properties, this is where you can perform your link click action. You can also clamp or adjust the property value here (via this.properties[name]), and the property will update accordingly.
IDEInstance.OnRendererInit(renderer)
Called when a layout is opened containing instances of your plugin. You should load any textures or fonts here.
IDEInstance.OnRendererReleased(renderer)
Called when a layout containing instances of your plugin is closed. You should release any textures or fonts here.
IDEInstance.Draw(renderer)
Draw the object in the editor, if it is a "world" plugin type. Otherwise, Draw() is not called.

The edittime instance

The IDEInstance object has an instance member through which you can access information about the instance in the editor. It supports these methods:

instance.SetSize(size)
Set the object's width and height according to the cr.vector2 passed to size.
instance.GetSize()
Return a cr.vector2 with the width and height of the object.
instance.SetHotspot(p)
Set the hotspot according to the cr.vector2 point p. Hotspots are specified in texture coordinates, where (0,0) is the top left corner of the object, and (1,1) the bottom right, and (0.5, 0.5) in the middle.
instance.GetBoundingRect()
Return a cr.rect object specifying the object's axis-aligned bounding rectangle.
instance.GetBoundingQuad()
Return a cr.quad object specifying the object's bounding quad.
instance.EditTexture()
Either pf_texture or pf_animations must be specified. Invokes the image editor or animation editor respectively.
instance.GetTexture()
Return an object representing the object's current texture. If pf_animations is specified, this is a texture representing the first frame in the first animation.
instance.GetOpacity()
Return the object's current opacity, if it has one.

Edittime rendering

The OnRendererInit, Draw and OnRendererReleased functions pass a renderer object as a parameter. It supports these methods:

renderer.Quad(q [, opacity, uv])
Render the quad q (a cr.quad) with the current texture. opacity is optional, and uv can be a cr.rect specifying the texture coordinates to draw.
renderer.Line(a, b, color)
Render a line with the current texture from a to b (both cr.vector2 objects) with the specified color (use cr.RGB(r, g, b) to generate a color).
renderer.Fill(q, color)
Fill the quad q (a cr.quad) with solid color (use cr.RGB(r, g, b) to generate a color).
renderer.Outline(q, color)
Draw four lines outlining the quad q (a cr.quad) with the given color (use cr.RGB(r, g, b) to generate a color).
renderer.CreateFont(face_name, face_size, bold, italic)
Create a font object with the given parameters. Font objects support the method:
font.DrawText(text, rc, color, halign)
where text is the text to draw, rc is a cr.rect of the rectangle to draw the text inside, color is the text color, and halign is one of ha_left, ha_center or ha_right.
renderer.ReleaseFont(font)
Release a previously created font.
renderer.LoadTexture(texture)
Load the object's texture. Use this in OnRendererInit(). Pass the object's texture from instance.GetTexture().
renderer.SetTexture(texture)
Set the texture currently drawing with.
renderer.ReleaseTexture(texture)
Release a previously loaded texture. Use this in OnRendererReleased().
renderer.EnableTiling(enable)
Pass true to enable tiling textures, or false to disable. Tiling allows uv coordinates greater than 1, causing the texture to repeat.
Texture objects also support the following methods:
texture.GetImageSize()
Return a cr.vector2 representing the texture's width and height in pixels (regardless of the object's current size).
texture.GetFilename()
Return the current active filename of the texture. This may be in a temporary folder if the texture has been edited but not saved.
texture.GetID()
Return an arbitrary string identifying this texture.
Construct 2 Javascript SDK Manual 2020-06-05