Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gdevelop5:tutorials:basic-game-making-concepts [2018/10/13 03:36]
valiant_curiosity [Moving objects using built-in forces]
gdevelop5:tutorials:basic-game-making-concepts [2020/04/05 22:51] (current)
4ian
Line 1: Line 1:
 # Basic game making concepts: What you need to know to start with GDevelop # Basic game making concepts: What you need to know to start with GDevelop
  
-The basic concepts of GDevelop are simple. Read the following information to get started with the software. If you don't have GDevelop, [[https://​gdevelop-app.com/​download|download the latest version here]]!+The basic concepts of GDevelop are simple. Read the following information to get started with the software. If you don't have GDevelop, [[https://​gdevelop-app.com/​download|download the latest version here]].
  
-## Coordinates+## Showing things on the screen: the Objects
  
-Objects ​on the GDevelop ​screen/scene have an X and a Y coordinateThese coordinates correspond ​to the horizontal position (X-axis) ​and the vertical position (Y-axis) on the //Cartesian plane//.+Everything that is *displayed ​on the screen* is called ​an **"​Object"​**Different kind of objects can be used to display different game elements on the screen. For example, most game graphics are "​Sprite"​ objects, texts can be displayed with "​Text"​ objects ​and special effects like a fire or sparks can be created with "​Particle Emitters"​.
  
-The X-coordinate //​decreases//​ as you scroll ​to the left and //​increases//​ as you scroll ​to the right. The Y-coordinate //decreases// as you scroll upwards ​and //increases// as you scroll downwards.+## Positioning Objects in the world: Coordinates 
 + 
 +Objects on the GDevelop screen/​scene have **X and Y coordinates**. These coordinates correspond to the horizontal position (X-axis) and the vertical position (Y-axis) on the //Cartesian plane//. 
 + 
 +The X-coordinate //​decreases//​ as you go to the left and //​increases//​ as you go to the right. The Y-coordinate //increases// as you go down and //decreases// as you go up.
  
 {{ wiki:​pres_coord1.png }} {{ wiki:​pres_coord1.png }}
Line 17: Line 21:
 If you use trigonometric functions like the **sine** or the **cosine**, ​ you will need to express the angles in **radians**. (1 radian = 180/PI degrees and 1 degree = PI/180 radians. PI is the number which is approximately equal to 3.14159). If you use trigonometric functions like the **sine** or the **cosine**, ​ you will need to express the angles in **radians**. (1 radian = 180/PI degrees and 1 degree = PI/180 radians. PI is the number which is approximately equal to 3.14159).
  
-## Events and how objects are picked+## Events and how objects are selected by these Events
  
-Events, that you use to create the rules of your game, are composed of conditions and actions.+Events, that you use to create the rules of your game, are composed of conditions and actions. ​Most conditions and actions refer to objects: ​
  
-Most conditions and actions refer to objects. ​Conditions run a test on the objects. Actions manipulate the object.+Conditions run a **test** on the objects. ​ 
 +Actions ​**manipulate** the object. They can change the object position, appearance, etc...
  
 An action, without a condition, ​ refers to all objects. If you use an object for the first time in an event, GDevelop will test or modify **all objects** with this name in the scene. An action, without a condition, ​ refers to all objects. If you use an object for the first time in an event, GDevelop will test or modify **all objects** with this name in the scene.
 If you use the object in the same event again, GDevelop will test or modify only the objects which have been picked by the previous conditions. If you use the object in the same event again, GDevelop will test or modify only the objects which have been picked by the previous conditions.
  
-This process is an application of logic. ​For example, this event has no condition. It will delete **all** objects called "​Square":​+For example, this event has no condition. It will delete **all** objects called "​Square":​
  
 {{ :​gdevelop5:​tutorials:​delete-square.png?​nolink |}} {{ :​gdevelop5:​tutorials:​delete-square.png?​nolink |}}
Line 36: Line 41:
 <note tip>​**See it in action!** 🎮Open this example online: https://​editor.gdevelop-app.com/?​project=example://​object-selection</​note>​ <note tip>​**See it in action!** 🎮Open this example online: https://​editor.gdevelop-app.com/?​project=example://​object-selection</​note>​
  
-[[https://​editor.gdevelop-app.com/?​project=example://​object-selection|{{ :​gdevelop5:​tutorials:​objectselection-pickobject.png?400 |}}]]+[[https://​editor.gdevelop-app.com/?​project=example://​object-selection|{{ :​gdevelop5:​tutorials:​objectselection-pickobject.png |}}]]
  
 ## Events: the order is important ## Events: the order is important
  
-**The order of events ​is critical!**+The order of events **does matter**!
  
 Events at the top are executed first. Events are executed every time your game is displayed. This display is called a frame. It executes about 60 times per second. The following examples are **not** equivalent: Events at the top are executed first. Events are executed every time your game is displayed. This display is called a frame. It executes about 60 times per second. The following examples are **not** equivalent:
Line 48: Line 53:
 {{ :​gdevelop5:​tutorials:​delete-then-create-square.png?​nolink |}} {{ :​gdevelop5:​tutorials:​delete-then-create-square.png?​nolink |}}
  
-* The first pair of events actions ​creates ​a "​Square"​ object at coordinates X: 100. Y: 200 (100;200). Then the event deletes the created square immediately. **No** "​Square"​ is displayed on the screen. It's deleted just after being created. +* The first pair of events actions ​create ​a "​Square"​ object at coordinates X: 100. Y: 200 (100;200). Then the event deletes the created square immediately. **No** "​Square"​ is displayed on the screen. It's deleted just after being created. 
-* The second pair of events actions deletes all of the "​Square"​ objects from the scene/​screen. It then creates one "​Square"​ at the scene/​screen coordinates X: 100, Y: 200 (100;​200). ​ This event shows a  square is  **visible** on the scene (before being deleted at the next frame. It will, then, be recreated immediately.+* The second pair of events actions deletes all the "​Square"​ objects from the scene/​screen. It then creates one "​Square"​ at the scene/​screen coordinates X: 100, Y: 200 (100;​200). ​ This event shows a  square is  **visible** on the scene (before being deleted at the next frame. It will, then, be recreated immediately.
  
-## Moving objects using built-in forces+## Behaviors: pre-defined rules and logic for objects
  
-Moving objects can be achieved with **forces**. Forces are used to "​push"​ objects.+**Behaviors** allow to enhance an object with some *pre-defined logic*. Behaviors can be fairly simple, automating simple tasks or much more advancedFor example: ​
  
-You can specify:  +* A behavior ​can be used to *automaticallyremove an object from the game when it *goes out of the screen* ​(limiting the game memory usage).  
-  ​* the Cartesian coordinates ​of a force (i.e. X and Y, in pixels). +Another behavior can be used to *move objects on the screen with the keyboard arrows*
-  its polar coordinates (the force vector angle and length)+Yet another behavior can be used to allow the object to be *dragged on screenwith the mouse or by touching the object. 
-  * the **force damping**coefficient between 0 and 1+The *Physics* behavior is an example of an advanced behavior which make your objects move in realistic way, following the laws of physics.
  
-Each second, the force-length will be multiplied by the dispersiona value of 1 means that force will continue forever. A value of 0 will make it stop immediately. All intermediate values will cause the force to gradually stop.+**Objects** and **Behaviors** can be manipulated using events. You can read the pages about [[gdevelop5:objects|Objects]] and [[gdevelop5:​behaviors|Behaviors]] ​to know more about them.
  
-Some behaviors ​that you can add to your objects ​will move the objects by themselves. This negates ​the need to use forces. ​In this case see below:+<note tip>You can create *custom ​behaviors* for your objects. It's even recommended when your game grows. This allow you to put logic about what your objects ​are doing in the custom behaviors, rather than bloating ​the events sheet of the scene. You can [[gdevelop5:​tutorials:​how-to-make-behavior|read more in this article]].</​note>​ 
 + 
 +## Moving objects: using the built-in forces 
 + 
 +Moving objects can be achieved with **forces**Forces are used to "​push"​ objects. 
 + 
 +You can specify 
 +  * the coordinates of a force on the X and Y axis, in pixels, 
 +  * or its polar coordinates (the force angle, in degrees, and length, in pixels), 
 +  * if the force is instant (will only push "a bit" the object) or continuous (will keep pushing the object until it's removed).
  
 ### Example ### Example
Line 74: Line 88:
 ### Other ways of moving objects ### Other ways of moving objects
  
-Some behaviors, like the Physics engine or Pathfinding,​ may move the objects by themselves. In this case, it is better not to use the builtin forces system and instead rely only on actions provided by the extensions used.+Some "behaviors", like the Physics engine or Pathfinding,​ may move the objects by themselves. In this case, it is better not to use the builtin forces system and instead rely only on actions provided by these behaviors.
  
 <note tip>​**See it in action!** 🎮Open this example online: https://​editor.gdevelop-app.com/?​project=example://​move-object-with-physics</​note>​ <note tip>​**See it in action!** 🎮Open this example online: https://​editor.gdevelop-app.com/?​project=example://​move-object-with-physics</​note>​
  
-## Variables+[[https://​editor.gdevelop-app.com/?​project=example://​move-object-with-physics|{{ :​gdevelop5:​tutorials:​moveobjectwithphysics.png |}}]]
  
-Variables ​allow you to store **data**. ​ For example, a variable can store a number or a text. We might compare them to drawers or boxes where we can file notes. Any data can be stored in a variable, as long as it is in //text// or //number// format. Such things as the number of lives a player has remaining, a player'​s high-score, the number of bullets left, and/or the number of enemies killed are all examples of what can be stored in a variable. You are probably going to store numbers in variables as a common practice.+<​note>​These other ways of moving objects are explained in [[gdevelop5:​tutorials:​how-to-move-objects|this how-to page]].</​note>​ 
 + 
 +## Storing any information in memory: ​Variables 
 + 
 +A Variable allows ​you to store **data**. ​ For example, a variable can store a number or a text. We might compare them to drawers or boxes where we can file notes. Any data can be stored in a variable, as long as it is in //text// or //number// format. Such things as the number of lives a player has remaining, a player'​s high score, the number of bullets left, and/or the number of enemies killed are all examples of what can be stored in a variable. You are probably going to store numbers in variables as a common practice.
  
 {{ wiki:​pres_variable.png }} {{ wiki:​pres_variable.png }}
Line 91: Line 109:
  
 * **Global** variables are accessible from all the game scenes. For instance, they can be used to store the player'​s score across different levels/​scenes. * **Global** variables are accessible from all the game scenes. For instance, they can be used to store the player'​s score across different levels/​scenes.
-* **Scene** variables are only accessible from the scene they are  created in. They can be used for data that only concerns one scene. ​ A Scene variable would be able to access the time remaining to complete the level/​scene.\\+* **Scene** variables are only accessible from the scene they are created in. They can be used for data that only concerns one scene. ​ A Scene variable would be able to access the time remaining to complete the level/​scene.\\
 * **Object** variables only concern one object. For example, a hero can have a "​Health"​ or "​Ammo"​ variable. * **Object** variables only concern one object. For example, a hero can have a "​Health"​ or "​Ammo"​ variable.
  
-<​note>​Read more about variables on the [[gdevelop5:​all-features:​variables|Variables]] page. Variables are used a lot and you can see examples ​of all you can use them in most examples ​and in the tutorials.</​note>​ +<​note>​Read more about variables on the [[gdevelop5:​all-features:​variables|Variables]] page. Variables are used a lot in games: most examples use them and tutorials ​will make use of them too.</​note>​
-<note tip>Want to see how variables are used in a tutorial video? Check this tutorial [[https://​www.youtube.com/​watch?​v=SRfpBTgx-PY|Variables explained for Non-programmers]].</​note>​+
  
-## Time elapsed since last frame (TimeDelta)+<note tip>Want to see how variables are used in a video tutorial? Check this tutorial: ​ [[https://​www.youtube.com/​watch?​v=SRfpBTgx-PY|Variables explained for Non-programmers]].</​note>​ 
 + 
 +## An advanced notion: the "​time ​elapsed" ​since last frame (TimeDelta)
  
 The game evaluates events and repaints the screen several times per second: we say that the game is //​refreshed//,​ //updated// during a "​tick"​. How often this happens depends on your computer resources: a slow computer can render 25 frames per second, a fast one 60. GDevelop can usually make sure that this value is the same on all computers. However, the speed of some operations can change from computer to computer, for example, mathematical operations and the rendering of movements. The game evaluates events and repaints the screen several times per second: we say that the game is //​refreshed//,​ //updated// during a "​tick"​. How often this happens depends on your computer resources: a slow computer can render 25 frames per second, a fast one 60. GDevelop can usually make sure that this value is the same on all computers. However, the speed of some operations can change from computer to computer, for example, mathematical operations and the rendering of movements.
  
-To make the speed of changes constant, use the //​TimeDelta() expression//,​ which returns the time in seconds since the last frame.+To make the speed of changes constant, use the //`TimeDelta()expression//,​ which returns the time in seconds since the last frame.
 For example, don't do this: For example, don't do this:
  
Line 112: Line 131:
 * The first event is adding 20 to the variable every time the game is refreshed (i.e. as much as possible, up to 60 times per second). It's **not correct** to use such event as the speed of the increase of the variable will not be the same from computer to computer: we cannot predict the value of the variable after 10 seconds for example - as it depends on the number of frames of the game painted. * The first event is adding 20 to the variable every time the game is refreshed (i.e. as much as possible, up to 60 times per second). It's **not correct** to use such event as the speed of the increase of the variable will not be the same from computer to computer: we cannot predict the value of the variable after 10 seconds for example - as it depends on the number of frames of the game painted.
  
-* The second event is **correct and reliable** : The number 300 is multiplied by TimeDelta(). Thus, the variable will be increased at the same time on all computers. As  TimeDelta() returns a time in second, it allows you to quantify exactly the amount: In our case, the variable will grow at 300 units/​second. Thus, we can predicate that the life will increase by 3000 units in 10 seconds - whatever the number of frames painted during this time.+* The second event is **correct and reliable** : The number 300 is multiplied by TimeDelta(). Thus, the variable will be increased at the same time on all computers. As  TimeDelta() returns a time in second, it allows you to quantify exactly the amount: In our case, the variable will grow at 300 units/​second. Thus, we can predicate that life will increase by 3000 units in 10 seconds - whatever the number of frames painted during this time. 
 + 
 +<note tip>As GDevelop will run your game at a maximum of 60 images per second, you usually won't notice an issue if you're using the first event. It's still a good idea to keep an eye on this and use the version with `TimeDelta()` instead.</​note>​
  
-**Remember:**  Use //​TimeDelta() // when you want to continually add some amount to a value. If your action is meant to be launched only once (for example, during a collision where you then delete the object), it's ok to use a discrete value without TimeDelta - as it does not depend ​upon the speed of the game.+**Rule of Thumb:**  Use //​TimeDelta() // when you want to continually add some amount to a value. If your action is meant to be launched only once (for example, during a collision where you then delete the object), it's ok to use a discrete value without TimeDelta - as it does not depend ​on the speed of the game.
  
 <note warning>​When you're moving an object using forces, there is no need to use TimeDelta() as GDevelop automatically uses it.</​note>​ <note warning>​When you're moving an object using forces, there is no need to use TimeDelta() as GDevelop automatically uses it.</​note>​