Our game will be based on scenes. We already described the advantages of scenes in a Scenes dedicated chapter. Mainly, we can sum up the purpose of the scenes with these characteristics :
From here we will created a scene for each element our game will need :
So let’s create our first scene.
The Node2D is now added to the scene and is shown both in 2D editor (main window) and in Scene panel.
Scene can be saved with .scn and .xml extensions. If you want to keep control on the content and do some batch operation, you might prefer the second one. But keep in mind that usually .scn will give better performance at runtime.
But as we said, the game will have many scenes. So there is a need to define with which scene the game will begin.
The Bat is the main character of the scene. It will have a Sprite (or some other visual element), a Camera following it, and a collision area. When defining the Bat scene, we keep in mind the following points :
With this in mind, we have a technical sprcification we can provide the team for this scene:
These are the only requirements for the scene to work, everything else (including for example, the name and type of the sprite node) is up to the team, and somewhat irrelevant to us. They can add nodes, use different types of nodes, etc. It is up to the team to make it look good, and play balanced, and up to the producer to organize everyone to provide content to the scene.
The scene for the user interface shows information about the current game, such as the score, lives, player status, etc. In this case, we have just one Label that displays a number, with the current score. The code will look for a node called label and set a number to it.
In this case we use a CanvasLayer node as root, and add a labelcalled pointsas a child. Using CanvasLayer instead of just classic node let’s us define freely the z position of the gui. Viewport is supposed to be placed on 0, but we will also have a parallax background. So let’s set the layer value as 2 and the GUI should always be on top, whatever the scene trees are.
The obstacle scene is spawned by the main level. This scene has 2 damage areas (one in the top, one in the bottom), and a bonus area in the middle. If the player goes over the bonus area, a point is awarded. This scene will be very important to the game designer, because it exposes the parameters used to balance the game (in conjunction with the parameters exposed in the Bat scene). This can be a bit tricky to express, so be prepared to have many discussions with your Game Design team to make sure you can provide them all the options they need. Don't be afraid to provide basic elements, game designers don't need a pretty interface, they need freedom :) And sometimes they know the basics of programming (and sometimes they know a lot of programming, but don't count on this). Give them freedom, and they'll surprise you !
In our example, the Obstacle scene provides the following elements:
Once your game is working, we can go deeper in the production. It will be time to add objects to our world.
Now we have made a first element we can add it to our main scene and use it in context.
We are now done with instantiation. It really seems like we’ve done a copy-paste but using this method, any changes made to the original bat scene will be applied to instances. In term of team management it helps everyone work on its part at his own rythm, without having other contributors to worry about. On the other way, it is still important to verify is working well after deep changes. In this case, refer to game design documents or scene graph to know which part are affected.
The main scene instances everything together, and in this example serves as the main title screen. The main scene will also receive input and notify every element of events that happen during the game (collision between objects, game was reset, etc). There are many methods to structure your game and the communication between your game elements. Objects can send messages to each other (through method calls or other type of messaging), or they can all send events to a main scene. They can also broadcast their events through signals, that objects connect to, or sending messages to groups. It's up to you to decide, but keep in mind that level designers will want as much freedom as possible to instance objects around the level.
In our example scene, there are 2 animations : game_over and game_reset. These can be used to display/hide a title screen, or show messages to the user. (see chapter Animations to know more about animation factory)
There is also a parameter that controls how often the Obstacle scene spawns, called spawn_distance, which is the distance in pixels between 2 spawned obstacles.
At last we'll add a ParallaxBackground node (with 1:1 scaling).
Motion > Mirroring
property to the size of your sprite.The Scene panel displays the name of the instance, and at the right, a folder that shows it’s instance and then available script for it. If you right-click on the folder icon, Show Children menu will display its nodes directly from here.
We are now done with instantiation. It really seems like we’ve done a copy-paste but using this method, any changes made to the original bat scene will be applied to instances. In term of team management it helps everyone work on its part at his own rythm, without having other contributors to worry about. On the other way, it is still important to verify is working well after deep changes. In this case, refer to game design documents or scene graph to know which part are affected.
Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.
Vous devriez rafraîchir la page.