دليل المبتدئين في كونستركت 2

  • 0 favourites





51,157 visits, 61,157 views




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.


First, click the Event sheet 1 tab at the top to switch to the Event sheet editor. A list of events 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.

About events

As the text in the empty sheet indicates, Construct 2 runs everything in the event sheet once per tick. Most monitors update their display 60 times per second, so Construct 2 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 events then draw the screen".

Events run top-to-bottom, so events at the top of the event sheet are run first.

Conditions, actions and sub-events

Events consist of conditions, which test if certain criteria are met, e.g. "Is spacebar down?". If all these conditions are met, the event's actions are all run, e.g. "Create a bullet 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 functionality 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 basically runs like this:

Are all conditions met?

---> Yes: run all the event's actions.

---> No: go to next event (not including any sub-events).

That's a bit of an oversimplification. Construct 2 provides a lot of event 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

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

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

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.

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

Double-click the Every tick condition to insert it. The dialog will close and the event is created, with no actions. It should now look like this:

Now we want to add an action to make the player look at the mouse. 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:

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. The list of actions available in the Player object appears:

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.

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

These 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 2's flexibility.

Did you get an error that said "Mouse is not an object name"? Make sure you added the Mouse object! Go back to page 2 and check under "Add the input objects".

You might be wondering how you'd remember all the possible expressions you could enter. Luckily, there's the "object panel" which you should see floating above it. By default, it's faded out so it doesn't distract you.

Hover the mouse over it, or click on it, and it'll become fully visible. This serves as a sort of dictionary of all the expressions you can use, with descriptions, to help you remember. If you double-click an object, you'll see all its expressions listed. 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:

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


  • Order by
Want to leave a comment? Login or Register an account!