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.
PluginsPlugins 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 typesObject 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.
InstancesUsing 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.
BehaviorsBehaviors 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.
Instance variablesInstance 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.