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

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

Called whenever Construct 2 needs to create a new object type from your plugin.

The class representing an object type in the editor.

Called whenever Construct 2 needs to create a new instance from your plugin.

The class representing an instance in the editor.

Called whenever the user manually inserts a new instance in to the project. Typically this is done via the Insert Object dialog.

Called when an instance is double-clicked in the layout. You may want to invoke the texture or animation editor here.

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[name]), and the property will update accordingly.

Called when a layout is opened containing instances of your plugin. You should load any textures or fonts here.

Called when a layout containing instances of your plugin is closed. You should release any textures or fonts here.

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:

Set the object's width and height according to the cr.vector2 passed to size.

Return a cr.vector2 with the width and height of the object.

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.

Return a cr.rect object specifying the object's axis-aligned bounding rectangle.

Return a cr.quad object specifying the object's bounding quad.

Either pf_texture or pf_animations must be specified. Invokes the image editor or animation editor respectively.

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.

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.

Release a previously created font.

Load the object's texture. Use this in OnRendererInit(). Pass the object's texture from instance.GetTexture().

Set the texture currently drawing with.

Release a previously loaded texture. Use this in OnRendererReleased().

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:

Return a cr.vector2 representing the texture's width and height in pixels (regardless of the object's current size).

Return the current active filename of the texture. This may be in a temporary folder if the texture has been edited but not saved.

Return an arbitrary string identifying this texture.