• No results found

To insert an event, you must first click the Events tab and then click on the icon that says Add an event, which creates a new line in the Event window.

Each event begins with a number that identifies it, and is divided into two parts: the first where the conditions are defined, and the second where the actions are defined to be executed when the conditions are met.

Conditions Actions

Note: The actions and conditions of the events that will be presented below are available in both modes (Native and HTML5). There are more types of actions and conditions in the native mode, but only a few will be explored in this introductory text.

 Add conditions

To add a condition, double-click in the first rectangle of the event or click the tab that is displayed when the mouse is placed on the rectangle.

After this, another window unfolds that displays the different conditions that can be added. Below you can see the conditions window for the HTML5 mode:

All the conditions have a box that says: Invert the condition; if this box is checked, GDevelop will make

After this, in the events panel you will see two red arrows, at the beginning of the condition.

 Add actions

To add an action, you double-click on the second rectangle of the event or click the tab that is displayed when the mouse is placed on the rectangle.

After this, another window unfolds that displays the different actions that can be added. Below you can see the actions window for the HTML5 mode:

 Add a comment between events

Before you start adding events it is very important to acquire the habit of adding comments between events.

This is very useful for documenting each project. Each comment gives clues about how each part of the code works. In this way, when you need to change something, it doesn't need to study all of the code, but go directly to the part that requires a change.

To add a comment, you must be in the Events tab and click on Add a comment.

After this, a new window opens in which you can edit the comment and select the background and text color.

After this, will appear in the Events panel the commentary that was added, which could be seen in the following way:

In the following pages you will see a presentation of some of the main conditions and actions available to create events in GDevelop:

a. Scene events

Condition: At the beginning of the scene

This condition is activated by clicking on Add a condition, then click on the triangle that precedes the Scene condition and then the option At the beginning of the scene.

This condition is used to make actions, just in the moment when the scene starts.

Action: Change background color

To change the background color of the scene you click Add an action, then click on the triangle that precedes

b. Special Events

On some occasions, an event has actions that should not be activated several times in succession. What is needed is that the actions of the condition run only the first time that this condition is fulfilled.

A case to use for this condition is with the action to play a sound. Sometimes there is no sound, because the condition is fulfilled many times and this does not allow the sound to be played.

Condition: Trigger once while true

This condition is activated by clicking on Add a condition, then by clicking on the triangle that

c. Mouse Events

There are four (4) types of conditions for the mouse.

The first is to determine which mouse button was pressed, and the other two, to analyze which is the position of the mouse, both in the X axis as in the Y axis.

To enable some of these conditions you must click Add a condition, then click on the triangle that precedes the Mouse and touch condition, and then in any of the following options:

 Mouse Button down or touch held

 The cursor/touch is on an object

 Cursor X position

 Cursor Y position

d. Multi-touch Events

There are four (4) types of sub-conditions for multi-touch, which is located inside the conditions of Mouse and touch. The first is to determine if a touch on the screen has ended, the following to determine if it has initiated a new touch, and the other two analyze which position it is where the touch was made, both in the X axis as in the Y axis.

To enable any of these conditions, you must click Add a condition, then click on the triangle that precedes the Mouse and touch condition, then on the triangle that precedes the Multitouch

sub- A touch has ended

 A new touch has started

 Touch X position

 Touch Y position

e. Keyboard Events

There are three (3) types of conditions for the keyboard.

The first is to determine if any key was pressed, the second is to evaluate if an alphanumeric key was pressed, and the third determines which keys are pressed. Even the control keys as Enter, Shift, Ctrl, and so on.

To enable any of these conditions you must click Add a condition, then click on the triangle that precedes

the Keyboard condition and then in any of the following options:

 Any key is pressed

 A key is pressed (text expression)

 A key is pressed

f. Collisions

To create a condition of collision you should click Add a condition, then click on the triangle that precedes All Objects condition , click on the triangle that precedes the Collision sub-condition and then in the option Collision. In the window you must select the two objects that will be evaluated if they are on a collision

g. Sound and music events

The sound events are those that are used to play sound effects that are repeated each time the user makes an action. For example, the gunshot sounds (for a war game) or the sound of the character jumping (in the case of a platform game).

The music events are those that are used to play a track or song, which will sound in the background, giving the game some kind of sound atmosphere. For example, you can use this event to inform the player that he had little time left to finish the level, making the rhythm of the music, play much faster.

Action: Play a sound

To play a sound, click Add an action, then click on the triangle that precedes the Audio action, click on the triangle that precedes the Sounds on channels sub-action -and then the option Play a sound at a channel.

Action: Stop a sound

To stop a sound, click Add an action, then click on the triangle that precedes the Audio action, click on the triangle that precedes the Sounds on channels sub-action and then the option Stop the sound of a channel.

Action: Play music in the background

To play music in the background, click Add an action, then click on the triangle that precedes the Audio action, click on the triangle that precedes the Music on channels sub-action and then the option Play a music on a channel.

Action: Stop music

To stop the background music, click Add an action, then click on the triangle that precedes the Audio action, click on the triangle that precedes the Music on channels sub-action and then the option Stop the music on a channel.

h. Object Events Action: Delete Objects

To remove objects, click Add an action, then click on the triangle that precedes All the objects action, click on the triangle that precedes the Objects sub-action, then in the option Delete Object. After this, select the object to be deleted.

Action: Create objects

To create objects, click Add an action, then click on the triangle that precedes All objects action, click on the triangle that precedes the Objects sub-action and then in the option Create object. After this, select the object that is going to be created and define its position in the X axis and the Y axis.

Action: Create objects randomly

To create objects randomly, click Add an action, then click on the triangle that precedes All objects action, click on the triangle that precedes the Objects sub-action, and then in the option Create object. After this, select the object that is going to be created and define its position in the X axis a random value and for the Y axis the middle position of the screen. See the following example:

Here is generated a random value in the X axis, with the statement:

Random(SceneWindowWidth())

And for the position in the Y axis is set in half of the

Note: In case you use keyboard or mouse events, for the random creation of objects, it is recommended to add the condition Trigger once while true, since the application runs so quickly that many objects are generated by simply pressing a key or a mouse button.

So the event should look similar to this:

i. External Events Create an external event

The external events allow you to divide the game code into sections that make specific activities (such as for example, control the enemies), which facilitates understanding and studies the code later.

To add an external event do so by right-clicking on External events within the Project manager and then over the option Add external events.

After this, a new item will appear in the external events called External events, which you should rename according to the activity that this will carry out. To do this, right-click on the newly created external events item and click Rename.

GDevelop also offers the option to Edit as if the events were included to scene. If you want to use this option, then select one of the scenes.

Insert link to an external event

If you want to make use of an external event within a scene, you must insert a link to the external event. For this you click on the Events tab, then click Add and finally in Link.

After this, a new window appears where you can select the external event to be used, which in this case would be menu.

And in the events panel would be as follows:

j. Group of events

A group of events is a strategy to sort the code, which allows a set of events that will be included within the same group, with which you can hide or show the events that contains each event group. Normally the event groups are created by affinity. One group may contain the input events, another group the sound events, another can contain the collision events, and so on.

To create a group of events you need to click the Events tab, then click Add and finally in Group.

Then a new window opens in which you should assign a name to the group and select a background color:

After this, appearing in the events panel, the created group (in this case keyboard):

If you click the triangle at the beginning of the group you can show or hide the events that contains.

k. Events to convert data Converting a number to text

To convert a number to text you should use the function: VariableString(variable name)

An example to use this function would be to assign a text object the value of a numeric variable, to be shown as text. For this you click Add an action, then click on the triangle that precedes the Text object action and then Modify the text. There you should select the text object, then the sign of modification = and finally, in the text box, add the line VariableString(counter). In this case counter is the name of the variable.

Convert text to number

To convert text into a number you should use the function:

ToNumber(VariableString(txt)) An example to use this function would be to assign a numeric variable the contents of a text variable. For this you click Add an action, then click on the triangle that precedes the variables action and then in the option Value of a variable. There you should select the numeric variable, then select the sign of modification = and finally, in the text box, add the line ToNumber(VariableString(text)). In this case text is the name of the text variable .

l. Event to generate random numbers

To generate random numbers you should use the function:

Random(value)

Which generates random numbers between 0 and the value assigned within the function Random . For this you click Add an action, then click on the triangle that precedes the variables action and then in the option Value of a variable. Select the variable, then select the sign of modification = and finally, in the value box, click the icon of the expression editor that looks like an M lying down . M

After this, the window Edit the expression will open, here you need to click over Random, within the Other functions panel and the in the option random value.

This generates an expression of the following type:

Random()

And then within the parenthesis type the expression:

SceneWindowHeight() At the end will look like this:

Random(SceneWindowHeight()) And finally you click OK on all the windows.

m. Event for timing the game

For timing the game, you must create a condition that measure the time for a specific period. In this case we are going to create a stopwatch that counts seconds.

For this, click Add a condition, then click on the triangle that precedes Timers and time condition and then in the option Value of a timer. There you must define for how long the time will be measured, in this case the value 1 to measure second by second, and then you put a name to the stopwatch, in this case:

"secondstimer".

Following this, you must click Add an action, then click on the triangle that precedes the Timers and time action and finally in the option Reset a timer.

This allows you to reset the counter once the condition is met for each period (in this case, second by second).

Then you must create another action that allows you to increase in one (1) the value of the variable that is counting the time in seconds. For this you must click Add an action, then click on the triangle that precedes the variables action and then in the option Value of a variable. There you should select the variable, the sign of modification + and finally add the value 1.

This expression assigns to the seconds variable the value stored plus one (+1).

Finally the code might look like this:

PART THREE:

INTERFACE OF THE GAME

10. Instances, layers, order, cameras and scenes

Related documents