F1 - Open documentation
Ctrl+D - Duplicate object
KinematicBody2D
- Body that is controlled by user.
RigidBody2D
- Dynamic body that is not directly controlled by user.
StaticBody2D
- Static body like wall, floor, etc.
Area2d
- Used for 2D area that has on_body_entered
signals.
AudioStreamPlayer
- Sound player that have no location realted data.
AudioStreamPlayer2D
- Sound player that is related to specific point.
CanvasLayer
- Layer that has no position. Fits good for GUI.
Control
- Base class for all GUI nodes.
TextureRect
- For non interactive images and objects.
RayCast2d
- Has is_colliding()
API to detect if objects are close.
- Create
KinematicBody2D
scene for the player. - Create
AnimatedSprite
child node under player and set the animations. - Create
CollisionShape2D
and choose the needed shape (propably capsule). - Create script file for the player. Make sure it inherits
KinematicBody2D
. - Go to
Project Settings
->Input Map
and configure the input buttons.
- Create new user interface scene.
- Set
Layout
toFull Rect
. - Add chile node of
Texture Rect
and place there the background. - Make sure to set
Layout
toFull Rect
for the background node. - Add
VboxContainer
s andHboxContainer
s to layout all interface data. - Add label nodes for text. Set its font to be dynamic and load font data.
Here is interface scene example:
We can create scene instance and add it to other scene as a sub node.
For example, we can create Level scene, and add it an instance of player scene.
Use the "Instance Child Scene" button.
Use this button to go to the main scene from its instance.
Node subnodes can be locked. This can help for moving node and it child nodes together.
- Create TileMap node under the main level node.
- Import the level sprite sheet.
- Enable the line grid on the sprite sheet.
- Press "new auto tile".
- Adjust the tile grid so it matches the sprites.
- Set tile collision.
- Set the tiles on the tile map.
We can devide objects to layers.
Each layer can be renamed to more human readable name like player, level, etc.
Layer is represents the object's layer.
The mask is the layers that the object can interract with.
Camera should be child node of the player node.
Current
checkbox will allow camerat to follow player character.
Drag margin
and Smoothing->Speed
can toggle the sensitivity of the camera movments.
ParallaxBackground
should be child node of the camera.
ParallaxBackground
can have few ParallaxLayer
child nodes.
Each ParallaxLayer
should have child node of TextureRect
for the image.
Make sure to set ParallaxBackground
->Scroll->"Ignore Camera Zoom
".
ParallaxLayer
->Motion->Mirroring setting should allow to stretch the backgroud
over the whole level.
Use the ParallaxLayer
->Motion->Scale to controll how fast the background is moving.
Remmember that the most far object should have the lowest scale.
Use the ParallaxLayer
->Motion->Offset to controll the background location on the level.
Main scene is the scene that starts the first.
It can be set in Project Settings
.
Make sure to unset the Loop
flag on imported OGG files.
This way the sounds will be played once and not loop for ever.
Sounds can be loaded from the code. It allows one player to play different sounds.
Here is and example:
$DamageSound.stream = load("res://Sounds/enemy_dying.ogg")
$DamageSound.play()
Signal groups can be used to group logic in single functions.
For example:
GameRules signal group can have signals like "take_damage" or "game_over".
To define GameRules
signal group create GameRules.gd script under the game level scene. Then add the following code:
func _ready():
add_to_group("GameRules")
func end_game():
pass
// End game logic goes here
To call end_game signal, add the following code in the relevant scene code:
get_tree().call_group("GameRules", "end_game")
- Create new GUI scene fron
CanvasLayer
. - Add
Control
child node. - Set
Control
layout toFull Rect
. - Add
HBoxContainer
for all the data to be shown. - After GUI scene is ready, add instance of it under your level scene.
We can add and remove scene instances dynamically.
Here is an example, in which we add/remove TextureRect
scenes
on the GUI canvas:
func add_lives(lives_number):
# Adding heart images on the game GUI
while lives_number > $Control/Lives.get_child_count():
$Control/Lives.add_child(load("res://Scenes/heart.tscn").instance())
func remove_lives(lives_number):
# Removing heart image on the game GUI
if lives_number < $Control/Lives.get_child_count():
var heart = $Control/Lives.get_child(0)
heart.queue_free()
- Create new scene fron
Node2d
. - Create child node of
Area2d
. - Add
Sprite
andCollisionShape2d
. - Add child node of
AnimationPlayer2d
. - In the animation bottom tab, press
Add Track
. - In the
Add Truck
choose the setting you want to animate. - Create the animation.
- Set the animation to
autoplay on load
. - Set the animation to
loop
.
To create singleton file use the following steps:
- Create new script file.
- Go to
Project Settings
. - Go to
Autoload tab
. - Add your script.
- Enable the
Singleton
option for your script.
If your file is named Globals.gd
, you can access it globaly
from any file by writing Globals.variable_name
.