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:objects:base_object [2018/09/10 21:38]
4ian [Origin & Center]
gdevelop5:objects:base_object [2020/04/06 09:42] (current)
4ian [In the events editor]
Line 1: Line 1:
 # Common features to all objects # Common features to all objects
  
-In a GDevelop game everything on the screen is an object.+In a GDevelop gameeverything on the screen is an object.
  
 +## Add an object to the game
  
-## Add an object to our game +In a scene, we can add objects by simply clicking the add object button on the right, on the bottom of the objects list:
- +
-We can add objects ​to our game by simply clicking the add object button on the right+
 {{ :​gdevelop5:​objects:​add-object-button.png?​nolink&​400 |}} {{ :​gdevelop5:​objects:​add-object-button.png?​nolink&​400 |}}
  
-We can choose from many different type of objects with specific properties and purpose+You can choose from many different type of objects, all with specific properties and purpose:
-{{ :gdevelop5:​objects:​object-types.png?​nolink&​400 |}}+
  
-Depending on what type of object we have created, the editor, aspect of the object and the available features in the events will be different. As the goal of this page is to explain ​objects ​in general, we won't go in to details of these unique properties on each type. You can find [[http://wiki.compilgames.net/​doku.php/​gdevelop5/​objects|detailed information on each type of object here]].+{{ :gdevelop5:objects:base_object:​pasted:​20200406-092728.png?​nolink ​|}}
  
-## Add an instance ​to our scene+Depending on what type of object you have chosen, the editor, aspect of the object and the available features in the events will be different. As the goal of this page is to explain objects in general, we won't go in to details of these unique properties on each type. You can find [[http://​wiki.compilgames.net/​doku.php/​gdevelop5/​objects|detailed information on each type of object here]].
  
-We can add an object to our scene by selecting the object ​in the Object tab and then click in our scene to place an instance of that object. An instance is basically a copy of the object living on the scene. Each instance has its own variables, position, animations (for sprite objects), content (for texts), etc...+# Objects ​in the scene
  
-## Add objects to groups+## Add an instance on the scene
  
-We can add objects to groups. To do that just click the groups icon on the top +An object ​can be positioned ​on the scene by selecting ​the object ​in the Object tab (click/tap on it) and then drag them into the scene to put an *instance* ​of that objectAn *instance* ​is basically ​copy of the object ​living on the scene. ​Each instance has its own variables, position, animations (for sprite objects), content (for texts), etc...
-{{ :​gdevelop5:​objects:​groups-button.png?​nolink&​200 |}} +
-Once you clicked, it should open up the Objects groups tab where you can see the list of groups you might have. To add a group click the add group button +
-{{ :​gdevelop5:​objects:​add-group-button.png?​nolink&​400 |}} +
-After that you should see a new group in the list. +
-{{ :​gdevelop5:​objects:​group-group.png?​nolink&​400 |}} +
-To rename the group, right click on the group and select rename. +
-To add objects to the group, right click on the group and select edit group. +
- +
-In the next window click the choose object ​to add to group button and choose the objects you want to be the member ​of this group +
-{{ :​gdevelop5:​objects:​edit-group.png?​nolink&​400 |}} +
-Once you're done just click the Apply button on the bottom right corder +
- +
-The purpose of the groups ​is that when you start making your game you can refer to group instead ​of each object ​one by one. For example, you may want to add all kind of enemies to a group called "​Enemies"​ and once you done that you can just simply refer to the group "​Enemies"​ when you want to do something with all kind of enemies in your scene not just a specific kind or a specific one but to all of themMaybe freeze them all for a second when the player apply a special ability. +
- +
-# In the scene editor+
  
-We can change the position of an object by selecting the object in the scene editor and drag it. +On the scene editor, you can:  
-We can scale the object by selecting the object and drag one of the white scale points+change the position of an object by selecting the object in the scene editor and drag it. 
 +scale the object by selecting the object and dragging ​one of the white handles: 
 +* rotate the object by selecting the object and dragging the rounded white handle:
 {{ :​gdevelop5:​objects:​coin-selected.png?​nolink&​200 |}} {{ :​gdevelop5:​objects:​coin-selected.png?​nolink&​200 |}}
  
 +## Modifying Instance properties
  
-## In the Properties tab +When you select an instance ​in the scene editor, the properties ​panel on the left shows information about the selected instance(s). If it is not open, you can re-open it by clicking the properties button ​in the toolbar:
- +
-When we select an object ​in the scene editor, ​we should see the Object ​properties on the left and we can change more properties there. If it not open we can re-open it by clicking the properties button ​on the top+
 {{ :​gdevelop5:​objects:​object-propeties-button.png?​nolink&​200 |}}  {{ :​gdevelop5:​objects:​object-propeties-button.png?​nolink&​200 |}} 
  
-## Position+### Position
  
-We can change ​the position of the selected ​object ​by changing the X and Y values in the object ​properties ​tab +You can precisely set the position of the selected ​instances ​by changing the X and Y values in the properties:
-{{ :gdevelop5:​objects:​object-position-properties.png?​nolink&​400 |}}+
  
 +{{ :​gdevelop5:​objects:​base_object:​pasted:​20200406-092924.png?​nolink }}
  
 ## Angle ## Angle
  
-We can change ​the angle of the object ​by changing the angle value in the properties tab+You can set the angle of the instance(s) ​by changing the angle value:
 {{ :​gdevelop5:​objects:​object-angle-properties.png?​nolink&​400 |}} {{ :​gdevelop5:​objects:​object-angle-properties.png?​nolink&​400 |}}
-The angle can be any value from 0 to 360 
-note: The angle rotation is based on the default center points of the object/​sprite. Changing the center or origin does not affect the angle rotation. ​ 
  
 +The angle can be any value from 0 to 360 degrees. Remember this diagram to see what is the orientation of a given angle:
 {{ :​gdevelop5:​objects:​gdevelop_co.png?​nolink&​400 |}} {{ :​gdevelop5:​objects:​gdevelop_co.png?​nolink&​400 |}}
- 
  
 ## Z order ## Z order
  
-We can change the Z order of an object by changing the Z order value in the properties ​tab+You can change the Z order of an instance ​in the properties:
 {{ :​gdevelop5:​objects:​object-zorder-properties.png?​nolink&​400 |}}  {{ :​gdevelop5:​objects:​object-zorder-properties.png?​nolink&​400 |}} 
-The purpose of the Z order is basically ​to change the position of the sprite on the Z axis and by doing so we can control if the object is behind ​an other object ​or it is in front. We can use any value here. The lower value means the object ​is lower in the order and the higher value means it is higher.+ 
 +The purpose of the Z order is to allow to specify which object will be displayed first, when instances are overlapping. More precisely, you can control if the object is behind or in front of another object: when two objects are overlapping, ​the object ​with the lower value of Z order will be displayed behind ​the other. 
 + 
 +Values can be any integer, including negative numbers ​and 0. 
 {{ :​gdevelop5:​objects:​coin-bush-zorder.png?​nolink&​400 |}} {{ :​gdevelop5:​objects:​coin-bush-zorder.png?​nolink&​400 |}}
 On the above image the Z order of the bush on left is 2, the Z order of the coin is 1 and the Z order of the bush on the right is 0. On the above image the Z order of the bush on left is 2, the Z order of the coin is 1 and the Z order of the bush on the right is 0.
Line 73: Line 59:
 ## Layer ## Layer
  
-We can change ​the layer of an object in the properties tab +You can set the layer of an instance:
-{{ :gdevelop5:​objects:​object-layer-properties.png?​nolink&​400 |}} +
-By default each GDevelop scene comes with a single layer called the "Base layer" and this is where all objects are located in our scene but we can add more layers for various purposes and put any object on to any layer we wish. For example we can use a layer to add on screen controls or to add a menu, a map..etc only our creativity is the limit what we are going to use a layer for.+
  
-## Lock+{{ :​gdevelop5:​objects:​base_object:​pasted:​20200406-093010.png?​nolink |}}
  
-We can also lock the selected object ​by ticking the box in the properties tab +A layer acts as a *virtual container* for objects displayed on the screen. Objects are drawn on a layer, which is by default the **“base layer”**, and the layer is then drawn on the screen. A scene can have multiple layers. For example, there can be a layer to display controls on screen, another to display a menu, another for a map, and yet another for a background. 
-{{ :​gdevelop5:​objects:​lock-sprite.png?nolink&​400 ​|}} + 
-The purpose of this feature ​is to lock the sprite so we can not longer select it in the scene. There are times when we have lot of objects ​overlapping each other in our scene and it is make it difficult to select some of them as we keep selecting the ones we don't intend to. In such cases, ​we can lock the sprite so we can not select it and move it incidently.  +## Lock position/​angle 
-We can unlock a sprite ​by opening the instances ​tab which is displaying all the instances in our scene and select the object from the list.+ 
 +By ticking the box "Lock position/​angle ​in the editor",​ you can make the instance immovable in the editor: 
 + 
 +{{ :​gdevelop5:​objects:​base_object:​pasted:​20200406-093052.png?nolink |}} 
 + 
 +When the instance ​is locked, ​we can not longer select it in the scene. There are times when you have lot of object instances ​overlapping each other in your scene. This makes it difficult to select some of them as you keep selecting the ones you don't intend to. In such cases, ​you can lock the instances
 + 
 +You can unlock a locked instance ​by opening the instances ​panel, ​which is displaying all the instances in our scene and select the object from the list.
  
 ## Instance variables ## Instance variables
  
-We can add variables to our objects by clicking the edit variables button +The "​Instance ​Variables" table allows ​to specify ​variables that are specific ​to the selected ​instance:
-{{ :​gdevelop5:​objects:​instance-variables-property.png?​nolink&​400 |}}     +
-Variables ​are a whole new topic so we wont go in to details right now but a variables ​is basically a container ​that is holding some sort of value and we can compare and change this value at any point in our game. There are different type of variables in GDevelop. In this case the value inside an **instance variable** is going to be unique to our instance of the object. So for example we can use an instance ​variable to store the health of each individual enemy instance in our game and if the value of enemy health is 0 we wont kill all the enemies but only the ones that health variable is actually 0 and because the instance variable is unique to each individual instance, GDevelop going to know which instances need to be killed.+
  
 +{{ :​gdevelop5:​objects:​base_object:​pasted:​20200406-092023.png?​nolink |}}
  
-## Timers +variable is basically ​container that is holding ​value (a number, a text), which can be compared ​and modified during ​the game. There are different type of variables in GDevelopIn particular each object can *define* variablesWhen the game is running, each *instanceof the object living on the scene will have its own variables.
-Objects can hold their own timers, and each timer will be unique for each instance. Object timers are useful to make instances to launch actions after/every X seconds.\\ +
-classical use would be to simulate fire rates: If you have single tank enemy you could use scene timer so every 3 seconds this tank can fire (create ​bulletand reset the timer so the tank can shoot again; now if you have 2 tanks and use a scene timer you'll notice both tanks shoot at the same time, because they are sharing the same scene timer, so you should create a second scene timer, independent from the first one to make the second tank to shoot; but if you have 100 tanks?, will you create 100 scene timers, one per instance?... you could... but here's when object timers give you a handreplacing every condition/​action using the scene timer with the conditions/​actions to use object timers GD will do the job for you and create a timer inside ​each tank instance!, and it will work as you expect, check if the timer "​fire_rate" ​of tank is greater than 3 seconds will pick the tanks that can shoot only, reset the timer after shooting ​will reset the timer of the shooting instances only, etc.+
  
-You can read more about timers here: [[gdevelop5:​all-features:​timers|]]+<note tip>For example, the object "​BlueEnemy" ​can have a variable *Health* set to 100. During the game, there can be multiple instances of this blue enemy. **Each instance** will have its own Health variable, which is by default 100 and can vary independently from other variables.</​note>​
  
 +The table allows you to specify variables that are specific to the selected instance. For example, if you have objects representing boxes with gold on the scene, you can modify the variable named "​Gold"​ of each instance to set a different number. Then in the events, when the player collides with a box, you can read the variable value to add it to the player gold amount.
  
 ## Custom size ## Custom size
  
-We can change the size of our objects by enabling the custom size in the properties ​tab and enter the custom ​Width and Height ​dimensions in pixel +You can change the size of your objectsby enabling the custom size in the properties ​panel, ​and then enter the custom ​*width* ​and *height* ​dimensions in pixels:
-{{ :gdevelop5:​objects:​customsize-properties.png?​nolink&​400 |}}+
  
  
-# In the events editor+{{ :​gdevelop5:​objects:​base_object:​pasted:​20200406-093137.png?​nolink |}}
  
-We can change and manipulate the properties of an instance or group of instances also using events. And this exactly what game making as all about in GDevelop, to manipulate objects in real time as we play our game and we can do just that using events. As the events and events editor is out of the scope of this page, we won't go in to details right now but only share some example projects that you can open and play around with it. To give you a kick start, We can show you where the events editor is located.+# Object groups
  
-## The events ​tab+An object group is a set of objects. For example, a group called "​Enemies"​ can contain the object "​Mushroom",​ "​Bomb",​ "​Dinosaur"​. You can then use the name of the group in the events ​to refer to all the objects contained in the group.
  
-To open the events editorjust click the events tab on the top next to the scene tabIt should be in the format "scene-name(EVENTS)"By default our scene is called "​NewScene"​ so don't be surprised ​to see maybe "​NewScene(EVENTS)" instead.  +This makes possible to create events that applies to lots of objects without repeating events multiple times, increasing performance of your game, maintainability and readability of your events. 
-{{ :​gdevelop5:​objects:​events-tab.png?nolink&​400 ​|}}+ 
 +To open the Groups Editor, click the groups icon on the toolbar: 
 +{{ :​gdevelop5:​objects:​groups-button.png?​nolink&​200 |}} 
 + 
 +In the Groups Editor are listed all the groups of the scene (and global groups too, which are available in all scenes of the game). To add a group click on the button on the bottom of the list: 
 +{{ :​gdevelop5:​objects:​add-group-button.png?​nolink&​400 |}} 
 + 
 +A new group is added to the list:  
 +{{ :​gdevelop5:​objects:​group-group.png?​nolink&​400 |}} 
 + 
 +* To change the name of the group, right click on the group and select *Rename*. 
 +* To add objects to the group, tap or click the group. 
 + 
 +In the window that open to edit the group, click on the bottom field and choose an object ​(or type the name of an objectto add it to the group 
 + 
 +{{ :​gdevelop5:​objects:​base_object:​pasted:​20200406-093739.png?nolink |}} 
 + 
 +# Variables 
 + 
 +Each object can contain variables, which are memory cells that you can use to store information. When the game is running, each *instance* of the object living on the scene will have its own variables. 
 + 
 +Read [[gdevelop5:​all-features:​variables|this page]] to learn more about variables. 
 + 
 +# Timers 
 + 
 +Objects can hold their own timers, and each timer will be unique for each instance of the object living on the scene. Object timers are useful to make instances to launch actions after/every X seconds. 
 + 
 +For example, a classic usage is to simulate shooting bullets. If you have a single tank on the scene, you could use a scene timer so that every 3 seconds, this tank can fire (create a bullet) and then reset the timer (so the tank can shoot again). 
 + 
 +The issue is that if you have 2 tanks and use a scene timer you'll notice both tanks shoot at the same time, because they are sharing the same scene timer. 
 +You need to have two separate timers, independent from each other, to make the second tank to shoot at its own rate. But what if you have 100 tanks? You don't want to create 100 scene timers, one per instance. 
 + 
 +This is when object timers are getting useful: replace every condition/​action using the scene timer with the conditions/​actions to use object timers. During the game, GDevelop will create a timer inside each tank instance. When you will be using a condition to check the value of a timer, only the instance that have a timer that have a value in seconds that is greater to the number you've entered will be picked. 
 + 
 +You can read more about timers here: [[gdevelop5:​all-features:​timers|]] 
 + 
 +# Visibility 
 + 
 +By default, object instances are all marked as visible, meaning that they are displayed on the screen. Using events, you can **hide** any instance during the game. An hidden object instance won't be displayed anymore, but will still live on the scene (reacting to collisions, and following all other events as usual). 
 + 
 +<note tip>Some objects, like Sprite or Text objects, can also have an **opacity**. The opacity, between 0 and 255, defines how transparent an object is (0 being fully transparent,​ 255 is the fully opaque and is the default). This can be changed independently from the visibility.</​note>​ 
 + 
 +# In the events editor
  
-Once you clickedyou should see all the events below that actually make our game. You can find more information on the events ​on the wiki+You can change and manipulate the properties of an instance of an objector of multiple instances, using events during the game. This is even what game making is all about in GDevelop: to manipulate objects in real-time as we play the game. As the events ​and events editor are out of the scope of this page, refer to [[gdevelop5:​tutorials:​basic-game-making-concepts|the basic game making concepts]] page to get started.
  
 +* All objects share the **same common features** (like position, angle and everything that is written on this page), and there are a lot of conditions and actions that you can use for all objects. You can [[gdevelop5:​objects:​base_object:​events|read more about the common conditions/​actions for all objects here.]]
 +* Objects can also provides you with specific feature. For example, [[gdevelop5:​objects:​sprite|Sprite objects]] can have animations, and the animation being played can be changed using an action. Find **more information in the [[gdevelop5:​objects|page of each specific object]]**.