Beginner's guide to Construct 3

1926

Index

Features on these Courses

Contributors

Stats

1,297,620 visits, 3,768,411 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 20 Sep, 2017. Last updated 24 Jun, 2024

Event blocks

First, click the Event sheet 1 tab at the top to switch to the Event Sheet View. A list of event blocks is called an Event sheet, and you can have different event sheets for different parts of your game, or for organisation. Event sheets can also "include" other event sheets, allowing you to reuse events on multiple levels for example, but we won't need that right now.

Event sheet tab

About events

As the text in the empty sheet indicates, Construct runs everything in the event sheet once per tick. Most screens update their display 60 times per second, so Construct will try to match that for the smoothest display. This means the event sheet is usually run 60 times per second, each time followed by redrawing the screen. That's what a tick is - one unit of "run the event sheet then draw the screen".

Event sheets are run top-to-bottom, so event blocks at the top of the event sheet are run first.

Conditions, actions and sub-events

Event blocks consist of conditions, which test if certain criteria are met, e.g. "Is spacebar down?". If all these conditions are met, the event block's actions are all run, e.g. "Create a spell object". After the actions have run, any sub-events are also run - these can then test more conditions, then run more actions, then more sub-events, and so on. Using this system, we can build sophisticated logic for our games and apps. We won't need sub-events in this tutorial, though.

Let's go over that again. In short, an event block basically runs like this:

Are all conditions met?

  • Yes: run all the event block's actions.
  • No: go to next event (not including any sub-events).

That's a bit of an oversimplification. Construct provides a lot of event sheet features to cover lots of different things you might need to do. However, for now, that's a good way to think about it.

Your first event block

We want to make the player always look at the mouse cursor. It will look like this when we're done:

The first event

Remember a tick runs every time the screen is drawn, so if we make the player point at the mouse cursor position every tick, they'll always appear to be facing the mouse cursor.

Let's start making this event. Double-click a space in the event sheet. This will prompt us to add a condition for the new event.

Creating a condition

Different objects have different conditions and actions depending on what they can do. There's also the System object, which represents Construct's built-in features. Double-click the System object as shown. The dialog will then list all of the System object's conditions:

System conditions

Double-click the Every tick condition to create an event with it. The dialog will close and the event is created, with no actions.

Now we want to add an action to make the player look at the mouse cursor. Click the Add action link to the right of the event. (Make sure you get the Add action link, not the Add event link underneath it which will add a whole different event again.) The Add Action dialog will appear:

Creating an action for the Player object

As with adding an event, we have our same list of objects to choose from, but this time for adding an action. Try not to get confused between adding conditions and adding actions! As shown, double-click the Player object, for it is the player we want to look at the mouse cursor. The list of actions available in the Player object appears:

Player object actions

Notice how the player's 8-direction movement behavior has its own actions. We don't need to worry about that for now, though.

Rather than set the player's angle to a number of degrees, it's convenient to use the Set angle towards position action. This will automatically calculate the angle from the player to the given X and Y co-ordinate, then set the object's angle to that. Double-click the Set angle towards position action in the list.

Construct now needs to know the X and Y co-ordinate to point the player at:

Parameters dialog

The X and Y fields are called the parameters of the action. Conditions can have parameters too, but Every tick doesn't need any.

We want to set the angle towards the mouse position. The Mouse object can provide this. Enter Mouse.X for X, and Mouse.Y for Y. These are called expressions. They're like sums that are calculated. For example, you could also enter Mouse.X + 100 or sin(Mouse.Y) (although those particular examples might not be very useful!). This way you can use any data from any object, or any calculation, to work out parameters in actions and conditions. It's very powerful, and a sort of hidden source of much of Construct's flexibility.

You might be wondering how you'd remember all the possible expressions you could enter. Firstly, you might notice Construct shows some lists as you type. This is called autocomplete and helps show what you can type at each point in an expression. Secondly, there's also the Expressions Dictionary which lists them all. If there's room on your screen, it will appear faded out, so it doesn't distract you until you need it. If it's not there, you can click Find expressions to open it. You can double-click an object in the Expressions Dictionary to see a list of all its expressions. If you double-click an expression, it will also insert it for you, saving you from having to type it out.

Anyway, click Done on the parameters dialog. The action is added! As you saw before, it should look like this:

The first event

There's your first event block! Try running the game, and the player should now be able to move around as before, but always facing the mouse cursor. This is our first bit of event sheet logic.

Disabled Comments have been disabled by the owner.