Posts

Showing posts with the label godot

[GODOT] Animate camera depending on touch screen events (C#)

Image
If you develop a 2D game for mobile, like a RPG game seen from top (Zelda like for instance), and you want to navigate on your map just by dragging the screen, here is the simple way to implement it in GODOT. In your level scene you have to add a "Camera" Node and make it the current one: public override void _Ready() { // Ensure the camera is set as current Current = true; } Then create the associated Camera script (in this example in C#). You have to handle Godot input events to animate the camera. The events to manage are: - InputEventScreenTouch - InputEventScreenDrag The goal is to determinate the delta amount of  horizontal & vertical spaces that have been dragged by the user. You can see an example of handling these events in the following code snippet (camera script):  using Godot; using System; public partial class camera : Camera2D { private Vector2 _touchStartPosition = new Vector2(); private bool _isDragging = false; // Call...

[GODOT for beginner tips] Global app's variables, states...

Image
While trying to develop my first game, I was wondering how to manage my game's "CONTEXT". Like maybe the current level, the global player's score or any other "GLOBAL" variables. GLOBAL variables (static in C#) can be used from any script. 1- Create a "global" script This is the script containing global variables and methods that will be accessible from every other script. Below here is an example of a global script called "App.cs": ==> you can see a static variable called "MainScene". This is the scene that can be accessible from everywhere (like a MENU scene for instance). 2- Make your script global In your project settings, find the "AutoLoad" tab and ACTIVATE the script "Global variable" parameter. Then you will be abble to access the script from everywhere. 3- Example of accessing the global variables In my mainscene script, I instantiate the app's (app.cs script) global variable by accessing it ...