Objects

In Construct 2 objects perform most of the useful work in a project. Most of the things you see in a Construct 2 game are represented by objects, and there are also hidden objects for other purposes (e.g. audio playback).

When inserting a new object, typically you first choose the plugin in the dialog (e.g. Sprite). This then creates an object type (e.g. TrollEnemy). When the mouse turns to a crosshair this allows you to place the first instance, and you can duplicate the instance to create more of them.

Understanding the differences between them is essential to use Construct 2 effectively, especially object types and instances. Objects consist of the following parts, summarised below. There are also manual sections that go in to more detail on each part.

Plugins
Plugins define a kind of object. For example, a Sprite is a kind of object, and the Audio object is a different kind. These are defined by the Sprite plugin and Audio plugin respectively.

Javascript programmers can make new plugins (and behaviors) using the Javascript SDK.

Object types
Object types define a 'class' of an object. For example, TrollEnemy and OgreEnemy could be different object types of the Sprite plugin. They have different animations and events can be applied separately to make them look and act differently, despite the fact they are both Sprite objects.

Instances
Using the previous example, if there were four TrollEnemy objects in a layout, these are instances of the TrollEnemy object type. There is only one TrollEnemy object type no matter how many instances are created. Instances all share the events and artwork for TrollEnemy. Similarly, there could be multiple instances of the OgreEnemy object type.

Instance variables
Instance variables are added to an object type and store numbers or text per instance. For example, if you want monsters to all keep track of their own health counter, you could add a health instance variable. This is essential for making interesting games - instance variables are very useful for making instances work independently of each other.

Behaviors
Behaviors can be added to object types to add pre-packaged functionality. For example, the 8 direction behavior can be added to a Sprite, and it can instantly move around with the arrow keys. This helps speed up development and increase productivity. Behaviors are not intended to do everything in your game for you: the event system is where the majority of your game logic will be defined. Behaviors are essentially time-savers and shortcuts. Most behaviors can be replicated with events, but it simply is far more time consuming to do so. Behaviors are very customisable, but if a behavior isn't doing quite what you want it to, you can usually resort to reproducing it in a customised way with events.

All instances of an object type use its behaviors. You cannot add a behavior to only some of the instances - they all use the behavior - although you may be able to enable or disable the behavior for individual instances.

Effects
Effects change the visual appearance of an object. Effects do not work on all platforms, because it requires WebGL support. However, fallbacks can be set up so everything still appears reasonably when WebGL is not supported. Note effects are separate to the blend mode which is supported on all platforms.

Families
Families are groups of object types. This can help avoid repeating events for different object types in large projects.

Containers
Containers are an advanced feature for picking a group of instances at the same time in events. This is useful for building composite objects (objects made from multiple objects, such as a tank made from a base sprite and a turret sprite).

Tags: