Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Godot 4 Game Development Cookbook
Godot 4 Game Development Cookbook

Godot 4 Game Development Cookbook: Over 50 solid recipes for building high-quality 2D and 3D games with improved performance

eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Colour book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Godot 4 Game Development Cookbook

Transitioning to GDScript 2.0

In Godot 4, the GDScript language backend was rewritten, allowing the runtime to be faster and more stable than it was in Godot 3.x. Some additions to the language were also implemented, which we will look at in this chapter: annotations that replace some keywords, such as export; the set and get properties, which replace setget; the await keyword, which replaces yield; and the super keyword, which refers to the parent class object and makes it easier to call the parent class methods.

Typed arrays now allow us to create arrays of a specific type such as all strings, which helps to cut down on errors. We will look at two ways to write a lambda function with a button signal along with other examples using lambda functions. We will also look at two callable static methods and how to use callables with signals.

In this chapter, we will cover the following recipes:

  • Investigating annotations in Godot 4
  • Using properties with getters and setters
  • Using the new await keyword and coroutines
  • Using the super keyword to call a function
  • Working with typed arrays
  • Working with lambda functions
  • Using callables with signals

Technical requirements

For this chapter, you need the standard version of Godot 4.0 or later running on one of the following:

  • Windows 64-bit or 32-bit
  • macOS
  • Linux 64-bit or 32-bit
  • Android
  • Web Editor

You can find the code and the project files for the projects in this chapter on GitHub: https://github.com/PacktPublishing/Godot-4-Game-Development-Cookbook/tree/main/Chapter%202.

Investigating annotations in Godot 4

In this recipe, we will first look at @export and some of the variations associated with that annotation and then show how to use @onready.

Getting ready

For this recipe, open Godot 4 and start a new project called Chapter 2.

How to do it…

To investigate annotations, we will use each in a script by doing the following:

  1. Open a new project in Godot.
  2. In the Scene tab, click 2D Scene.
  3. Click on the paper icon above Node2D and to the right of the filter Search box or in the Inspector tab under Node | Script. Click <empty>, then select New Script, and name the script Annotations.
  4. Click on Script at the top of the editor to look at the new script we added.
  5. @export is the same as export in Godot 3.x, so we will add a score to the node so we can see it in the Inspector tab:
    1  extends Node2D                           
    2     
    3  @export var score = 0
  6. As you saw from the auto-completion, there are new @export options available now. Let’s add @export_range() to line 4:
    4  @export_range(0, 100, .1) var input_range

Note

This gives a range from 0 to 100 in increments of .1 to the input_range variable, which you can change in the Inspector tab.

  1. We can show named enum values in the Inspector tab by adding the following to lines 5 and 6:
                                                          
    5    enum WeatherEnum {Sunny, Rainy, Cloudy = -1}
                                                       
    6    @export var weather: WeatherEnum
  2. On line 7, let’s add a file to show up on the Inspector tab using @export_file:
    7    @export_file("*.txt") var file
  3. Click on Node2D in the Scene tab. Then, click on + under Scene in the Scene tab to bring up the Create New Node window.
  4. Then, type camer2d in the Search box. Select and add Camera2D to Node2D.
  5. The onready keyword is now @onready. We will add a Camera2D node and use @onready with the camera on line 7:
    8    @onready var camera = $Camera2d
  6. Click on Node2D at the top of the tree in the Scene tab to see everything we used with @export in the Inspector tab.
Figure 2.1 – Annotations.gd

Figure 2.1 – Annotations.gd

How it works…

We added a score variable so we can could see it in the Inspector tab using @export instead of the export keyword.

We added @export_range(0, 100, .1) var input_range to show a range of 0 to 100 that snapped the value in .10 increments. You could also just use @export_range (0, 100) var input_range or @export_range (0, 100) var input_range: float.

We created an enum and then we used @export var weather: WeatherEnum to put the enum into the weather variable so we could see it in the Inspector tab. You could also do @export_enum(Sunny, Rainy, Cloudy) var weather.

We used the @export_file("*.txt") var file to show how a file is seen in the Inspector tab.

We added a Camera2D node to Node2D so we could use @onready with it. First, we just used @onready var camera = $Camera2d to add the Camera2D node to the camera variable.

Using properties with getters and setters

In Godot 4, the setget keyword is gone and has been replaced by using properties, so you don’t have to use dedicated functions. We will go through some examples of how to use getters and setters.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and add Node2D. Click on the word Scene in the top menu next to Project, then select Save Scene As, and name it Properties.

How to do it…

There are two ways we can use getters and setters. The first is like Godot 3.x, where we assign get and set to functions. The second way is to define get and set after we declare the variable. First, let’s create a button:

  1. In the new scene named Properties that you created, add a Button node and make it big enough to see.
Figure 2.2 – Creating a Button node

Figure 2.2 – Creating a Button node

  1. Add a script named Properties.gd to the Button node and delete everything except for line 1.
  2. At the top center of the editor, left-click on 2D in the Workspace section. Add a signal to the Button node by going to the Node tab to the right of the Inspector tab located under BaseButton and selecting pressed():
    1  extends Button       
    2                                                 
    3     
  3. The setget keyword used in Godot 3.x is now gone. We will assign get and set to functions as was done in Godot 3.x:
    5  var value: int = 10: set = set_value, get = get_value                         
    6                                                   
    7  func set_value(new_value: int) -> void:            
    8     value = new_value                          
    9     print('setter', str(value))               
    10             
    11 func get_value() -> int:                         
    12    print('getter', str(value))               
    13    return value                              
    14            
    15 func _on_pressed():                              
    16    value -= 1                              
  4. Now click the Run the current scene button or hit the F6 key. Look at the Output section in the bottom panel.
  5. Highlight lines 5–13 and hit Ctrl + K to comment out these lines.
  6. Now we will try using a variable declaration and no functions. Let’s start on line 15. Lines 23 and 24 should still be there from step 4. They were lines 15 and 16:
    15 var value: int = 10:            
    16     set(new_value):             
    17        value = new_value                         
    18        print('setter', str(value))          
    19     get:                                        
    20        print('getter', str(value))          
    21        return value                              
    22             
    23 func _on_pressed():                             
    24     value -= 1                         
  7. Now click the Run the current scene button or hit the F6 key.

How it works…

We added a button and connected the pressed() signal so we could see that the getters and setters were working.

In lines 7–9, we created the set_value setter function with an integer parameter called new_value. This function does not return a value so we used -> void:. We then made value equal to new_value, and finally, we printed setter with value.

In lines 11–13, we created the get_value getter function, which returns an integer, so we used -> int:. We printed getter with value and then we returned value. In line 16, we added value = value – 1 to the _on_pressed() function that was created when we hooked up the signal in step 3.

We entered the code to call the get and set functions as was done using the getset keyword in Godot 3.x. In line 5, we created a variable called value, which is an int value equal to 10. We then assigned set to the set_value function and get to the get_value function.

Figure 2.3 – The GDScript and console output results

Figure 2.3 – The GDScript and console output results

When the button was clicked, the value variable in the setter was decreased by one and then printed on the console, as well as the value getter variable before and after the button was pushed, to show that the getter and setter were working.

We commented out lines 5–13 so we could use the get and set properties with the variable declaration.

On line 15, we created an integer variable called value and assigned it to equal 10. Then, on line 16, we used the set property with new_value as the parameter. On lines 17–18, we made value equal to new_value and printed setter with value. On line 19, we saw the get property. On lines 20–21, inside of the get property, we printed getter with value.

Figure 2.4 – The GDScript and console output results

Figure 2.4 – The GDScript and console output results

We select Run the current scene and notice that we get the same output on the console as we did when we used functions. The value variable in the setter is decreased by one and then printed on the console, as well as the value getter variable before and after the button was pushed.

Using the new await keyword and coroutines

The yield keyword has been removed and replaced by the await keyword. You can use await with coroutines or signals. It pauses the function it is in and waits for a signal to be emitted, or if a called coroutine is finished, it then resumes the function where it was originally called.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and adding Node2D. Select Save Scene As and name it Await.

How to do it…

We will go through a very simple example of how await works with a coroutine using a button as a character dialogue box. When the button is clicked, it skips to the next character dialogue box:

  1. In the new scene named Await that you have created, add a Button node and make it big enough to see the text that we are going to place in it with code.
  2. Add a script named Await to Node2D and delete all of the default lines except line 1.
  3. Let’s use @onready and create a variable called button to reference our Button node:
    1  extends Node2D                                   
    2                                                  
    3  @onready var button = $Button
  4. On line 5, we will create a new function called game_dialogue() and call it in the _ready() function:
    4                                          
    5  func _ready():                               
    6     game_dialogue()                         
    7      
    8  func game_dialogue():                          
    9     button.text = "Dialogue text."               
    10    print("In the game_dialogue function.")     
    11    var next_dialogue = await skip_dialogue()    
    12    if next_dialogue:                    
    13       print("At the end of game_dialogue function.")
  5. On line 15, we created a new function called skip_dialogue():
    15 func skip_dialogue():              
    16    print("Now in the skip_dialogue() function.") 
    17    await button.button_up                    
    18    button.text = "New dialogue text."          
    19    print("At the end of skip_dialogue function." 
    20    return true
  6. Now click the Run the current scene button or hit the F6 key.
Figure 2.5 – GDScript for steps 3 to 5 (the code for Await.gd)

Figure 2.5 – GDScript for steps 3 to 5 (the code for Await.gd)

How it works…

We added a Button node and made it big enough for us to read the text on the button that we will code in later. Then we added a script called Await to Node2D and deleted all of the default lines except line 1.

We used @onready with the button variable so we could load the reference when the _ready() function was called.

We created a function called game_dialogue(). In line 9, we added text to the button. In line 10, we printed that we were in this function so we could see it in the console to see how the await keyword works. In line 11, we declared a variable called next_dialogue equal to the skip_dialogue() function written in step 5.

This is where the program will pause and go to the coroutine of the skip_dialogue() function. In lines 12–13, we have an if statement that checks that next_dialogue is true, and if so, then prints that we are back in the game_dialogue() function. For it to be true, the skip_dialogue() function has to run and return true.

We created the function called skip_dialogue(). In line 16, we printed to the console that we were now in this function. In line 17, we waited for the user to click the button. In line 18, we changed the text on the button. In line 19, we printed to the console that we were at the end of the skip_dialogue() function. In line 20, we return true so that when we go back to the game_dialogue() function, we can print the last print statement.

We selected Run the current scene.

You see In the game_dialogue function. and Now in the skip_dialogue() function. on the console before you click the button. The default text on the button is Dialogue text.. After you click the button, you see At the end of skip_dialogue function. and At the end of game_dialogue function. on the console and the text on the button is New dialogue text..

Using the super keyword to call a function

In Godot 3.x, we used to call a function of the parent class from a subclass by using the .function of the parent class. Now we use the super keyword. In the example, we will use in this recipe, we have SniperEnemyClass, which is inherited from DefaultEnemyClass. If we wanted to call the rifle function in DefaultEnemyClass from SniperEnemyClass, we would use the super keyword, but in Godot 3.x, we use .rifle().

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and clicking Node2D. Select Save Scene As and name it Super.

How to do it…

We will create two classes called SniperEnemyClass, which is inherited from DefaultEnemyClass. The DefaultEnemyClass class has two functions called rifle and orders. We will use the super keyword from SniperEnemyClass to call the two functions:

  1. Add a script named Super to Node2D and delete all of the default lines except line 1.
  2. Let’s start on line 11 and create DefaultEnemyClass:
    11 class DefaultEnemyClass extends Node2D:          
    12     func rifie():                   
    13        print("Basic rifle")                        
    14     func orders():                              
    15        print("Guard the front gate.")
  3. Now let’s create SniperEnemyClass starting on line 17:
    17 class SniperEnemyClass extends DefaultEnemyClass:
    18     func rifle():                              
    19        print("Sniper rifle")                   
    20        super.orders()                          
    21        super()
  4. We need to add a couple of variables to the _ready() function so we can see the output of the print statement on the console. Let’s start on line 3:
    3  func _ready():                           
    4      var enemy = DefaultEnemyClass.new()          
    5      var sniper = SniperEnemyClass.new()          
    6  
    7      enemy.rifle()                                
    8      enemy.orders()                              
    9      sniper.rifle()
  5. Now click the Run the current scene button or hit the F6 key.
Figure 2.6 – super keyword code (GDScript for steps 2–4)

Figure 2.6 – super keyword code (GDScript for steps 2–4)

How it works…

We added a script to Node2D and named it Super. Then we deleted all of the lines in the script except line 1.

We made a class called DefaultEnemyClass, which extends Node2D so, later, we can see the output on the console. In lines 12–13, we made a function called rifle to print out a rifle. In lines 14–15, we made a function called orders to print out the orders.

We made a class called SniperEnemyClass, which extends DefaultEnemyClass. In lines 18–19, we created a rifle function, which prints out a sniper rifle. In line 20, we called the orders function in the DefaultEnemyClass class using the super keyword. In line 21, we called the rifle function in DefaultEnemyClass from SniperEnemyClass using the super() keyword. As long as you are in a function that is in both parent and child classes, you can use super(). If you want to call a different function in DefaultEnemyClass, then you have to use super.function.

In lines 4–5, we created enemy and sniper instances for the two classes. In line 7, we called the rifle() function in DefaultEnemyClass to see which rifle was set as the default. In line 8, we called the orders() function in DefaultEnemyClass to see the enemy orders. In line 9, we called the rifle() function in SniperEnemyClass.

We ran the current scene. We saw Basic rifle, Guard the front gate., Sniper rifle, Guard the front gate., and Basic rife on the console.

We get the following console output when we run the current scene:

Figure 2.7 – super keyword console output

Figure 2.7 – super keyword console output

Working with typed arrays

In Godot 4, we can use typed arrays so if you are only going to use an array of strings, you can set the element type to String and Godot will throw an error if you try to put anything other than a string in that array. Types are validated at runtime and not when compiling, which causes slightly faster performance.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and adding Node2D. Select Save Scene As and name it TypedArray.

How to do it…

In this recipe, we are going to set up three arrays. The first is not a typed array, the second is a typed array, and the third infers the type of the array:

  1. Add a script named TypedArray to Node2D and delete all the default lines except line 1 and the _ready() function.
  2. On line 3, let’s create a regular array:
    1  extends Node2D  
    2                                                  
    3  var regular_array = [4, "hello",434]         
  3. On line 4, we will create a typed array of int. Try adding a string to this array:
    4  var typed_array: Array[int] = [16, 32, 64]        
  4. On line 5, we will create an inferred array of string. Try adding an integer to this array:
    5  var inferred_array := ["hi", "hello"]     
  5. On lines 7–10, in the _ready() function, we print out all the arrays to the console:
                                                      
    7  func ready():                                   
    8      print(regular_array)                         
    9      print(typed_array)                             
    10     print(inferred_array)                    
  6. Now click the Run the current scene button or hit the F6 key.
Figure 2.8 – GDScript for steps 2 to 5

Figure 2.8 – GDScript for steps 2 to 5

How it works…

We added a script to Node2D and named it TypedArray. Then we deleted all of the lines in the script except line 1 and the _ready() function. We created a regular array with two integers and one string value. We can put anything in this array.

We created a typed array of int and tried to enter a string in the array to see the resulting error. In step 4, we created an inferred array of String and tried to enter an integer into the array to see the resulting error.

We printed out all of the arrays to the console. We ran the current scene. We saw [4, "hello", 434], [16, 32, 64], and ["hi", "hello"] printed on the console.

Working with lambda functions

In this recipe, we are going to go through some examples of how to use lambdas in Godot 4. First, we create a lambda that takes a greeting parameter, then we will call the lambda and pass in "hello" to the parameter. In the next example, we declare a variable called health outside of the player_health lambda and call the variable inside of the lambda. We will learn two ways to write a lambda function with a button signal. Finally, we use a lambda function, moving the button across the screen with a tween.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and adding Node2D. Select Save Scene As and name it Lambda.

How to do it…

Let’s start by creating a Button node and referencing it to the button variable:

  1. Add a script named Lambda to Node2D and delete all of the default lines except line 1 and the _ready() function.
  2. In the new scene named Lambda that you created, add a Button node and make it big enough to see.
  3. Let’s use @onready and create a variable called button to reference our Button node:
    1  extends Node2D                                   
    2                                                  
    3  @onready var button = $Button
  4. On line 5, in the _ready() function, we create a lambda that will pass in "hello" to the lambda parameter greeting:
    5  func _ready():            
    6      var lambda = func(greeting):                   
    7          print(greeting)                         
    8      lambda.call("hello")                        
  5. On line 10, we declare a variable called health:
    10     var health = 100 
  6. On line 11, we create a lambda function called player_health:
    11     var player_health = func(): print("Current health ", health)
  7. On line 12, we call the player_health lambda function:
    12     player_health.call()                    
  8. On line 14, we create a lambda function to run when the button is pressed:
    14     button.pressed.connect(func(): print("button was pressed"))
  9. On lines 16–18, we create a lambda to run when the button is released:
    16     var button_released = func():               
    17         print("Button released")                  
    18     button.button_up.connect(button_released)
  10. On lines 20–21, we create a tween to move the button across the screen:
    20     var tween = create_tween()        
    21     tween.tween_method(func(pos): button.position.x = pos, 0, 500, 1)
  11. Now click the Run the current scene button or hit the F6 key.
Figure 2.9 – Lambda code (GDScript for steps 3–10)

Figure 2.9 – Lambda code (GDScript for steps 3–10)

How it works…

We added a script called Lambda to Node2D and deleted everything in the script except line 1 and the _ready() function. Then, we created a Button node in the Scene tab. In the Lambda script, we used @onready to declare a variable called button to the Button node.

We created a variable called lambda equal to the lambda function with the greeting parameter, which prints the greeting. Since lambdas are a type of callable, we call the lambda variable with the "hello" string to be used as the greeting.

We declared a variable called health and gave it a value of 100 in line 10. You can use variables from the outer class or outer function inside the lambda. In line 11, we created a lambda called player_health, which prints out Current health and the value of the health variable. In line 12, we call the player_health lambda to print out ("Current health ", health) to the console.

We pass the lambda as a function argument. When the pressed() button signal is emitted, Button was pressed will be printed to the console.

We essentially do the same thing we did last in the step except we use more than one line. When the button_up() signal is emitted, Button released is printed to the console.

On line 20, we create a tween. On line 21, we use a lambda in tween_method() to move the Button node from position (0) to position (500) with a duration of (1). If we wanted the button to go slower, we would increase the duration number.

We run the current scene. It shows the button move across the screen and on the console, you will see "hello" and "Current health 100". After you click the button, you will see Button was pressed and Button released.

Figure 2.10 – Button and console output

Figure 2.10 – Button and console output

Using callables with signals

In this recipe, we will see how callables can be used with signals. We will also look at the call and bind callable methods. Callables can be held in variables and passed into functions. As such, you can use them in arrays and in dictionaries as the key or the value.

Getting ready

For this recipe, create a new scene by clicking + to the right of the current Scene tab and adding Node2D. Select Save Scene As and name it Callables.

How to do it…

Let’s start by creating a Button node and referencing it to the button variable:

  1. Add a script named Callables to Node2D and delete all of the default lines except line 1 and the _ready() function.
  2. In the new scene named Callables that you created, add a Button node and make it big enough to see.
  3. Let’s use @onready and create a variable called button to reference our Button node:
    1  extends Node2D                                   
    2       
    3  @onready var button = $Button
  4. On line 8, we create a function called signal_callable():
    8  func signal_callable():             
    9      print("This method was called by the button pressed signal.")
  5. On line 5, in the _ready() function, we connect a callable signal to the signal_callable() function:
    5  func _ready():                                    
    6      button.pressed.connect(signal_callable)
  6. Now click the Run the current scene button or hit the F6 key.
  7. Let’s use the .bind method when we connect the signal. On line 6, add .bind after signal_callable:
    6      button.pressed.connect(signal_callable.bind("binding_")) 
  8. We need to add a parameter to the signal_callable function:
    8  func signal_callable(param):         
    9      print(param, "This method was called by the button pressed signal.")
  9. Now click the Run the current scene button or hit the F6 key.
  10. Let’s add a new function on line 11 called player_text:
    10 func player_text(param: String):                
    11     print(param)              
  11. Go to line 7, hit the Tab key, and add more code to the ready function.
  12. Let’s create a variable called pt equal to player_text:
    7      var pt = player_text      
    8      pt.call("Hello, NPC!")          
  13. Now click the Run the current scene button or hit the F6 key.

How it works…

We added a script called Callables to Node2D and deleted everything in the script except line 1 and the _ready() function. Then we created a Button node in the Scene tab. In the Callables script, we used @onready to declare a variable called button to the Button node.

We created a function that we want to run when the button pressed signal is true. Notice that we don’t have to connect the signal in the editor. We can use any method that we want.

In the _ready() function, we used the button reference to connect the signal_callable function when the signal pressed is true, which happens when the button is pressed.

We ran the current scene. In the console, we saw This method was called by the button pressed signal. after we clicked the button.

Figure 2.11 – Using callables with signals (code for steps 4–6)

Figure 2.11 – Using callables with signals (code for steps 4–6)

We used the callable bind method. In line 6, we added .bind like this:

button.pressed.connect(signal_callable.bind("binding_")).

We needed to add a parameter to the function and inside of the print statement to see what we added with bind.

We ran the current scene. In the console, we saw binding_This method was called by the button pressed signal. printed after we clicked the button.

Figure 2.12 – Using callable with the bind method (code for steps 7–9)

Figure 2.12 – Using callable with the bind method (code for steps 7–9)

We added a function called player_text, which takes a parameter called param that only accepts strings. It prints out the parameter that will be passed in when we use .call.

We created a variable for the player_text() function When you enter var pt = player_text, autocomplete wants to add the () at the end – make sure you delete it. We converted the function into a variable, so now we can use the function in arrays, dictionaries, or in any other way you can use a variable.

We ran it to see Hello, NPC! printed in the console.

Figure 2.13 – Using .call() with a variable of the function (code for steps 10–13)

Figure 2.13 – Using .call() with a variable of the function (code for steps 10–13)

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Take advantage of the new Vulkan renderer and 3D physics in Godot 4 to create high-quality games
  • Streamline your game development workflow with Godot’s new TileMap, TileSet, and Animation Editor features
  • Discover what’s changed in GDScript 2.0 and Shader additions to enhance your game development skills

Description

Want to transition from Godot 3 to 4? Look no further than the Godot 4 Game Development Cookbook. This comprehensive guide covers everything you need to become proficient with the latest GUI, GDscript 2.0, Vulkan 2D/3D rendering, shaders, audio, physics, TileSet/TileMap, importing, sound/music, animation, and multiplayer workflows. With its detailed recipes, the book leaves no stone unturned. The Godot 4 Cookbook begins by exploring the updated graphical user interface and helps you familiarize yourself with the new features of GDscript 2.0. Next, it delves into the efficient rendering of 2D and 3D graphics using the Vulkan renderer. As it guides you in navigating the new Godot 4 platform, the book offers an in-depth understanding of shaders, including the latest enhancements to the shader language. Moreover, it covers a range of other topics, including importing from Blender, working with audio, and demystifying the new Vulkan Renderer and the physics additions for 2D and 3D. The book also shows you how the new changes to TileSet and TileMap make 2D game development easy. Advanced topics such as importing in Godot 4, adding sound and music to games, making changes in the Animation editor, and including workflows for multiplayer in Godot 4 are covered in detail. By the end of this game development book, you’ll have gained a better understanding of Godot 4 and will be equipped with various powerful techniques to enhance your Godot game development efficiency.

Who is this book for?

The Godot 4 Game Development Cookbook is for seasoned game developers who want to acquire skills in creating games using a contemporary game engine. It is an invaluable resource for indie game developers and Godot developers who are familiar with Godot 3 and have some level of expertise in maneuvering the interface.

What you will learn

  • Speed up 2D game development with new TileSet and TileMap updates
  • Improve 2D and 3D rendering with the Vulkan Renderer
  • Master the new animation editor in Godot 4 for advanced game development
  • Enhance visuals and performance with visual shaders and the updated shader language
  • Import Blender blend files into Godot to optimize your workflow
  • Explore new physics system additions for improved realism and behavior of game objects
  • Experience innovative features by building multiplayer games in Godot 4
Estimated delivery fee Deliver to South Korea

Standard delivery 10 - 13 business days

$12.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 09, 2023
Length: 258 pages
Edition : 1st
Language : English
ISBN-13 : 9781838826079
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Colour book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to South Korea

Standard delivery 10 - 13 business days

$12.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

Product Details

Publication date : Jun 09, 2023
Length: 258 pages
Edition : 1st
Language : English
ISBN-13 : 9781838826079
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 139.97
Godot 4 Game Development Projects
$44.99
The Essential Guide to Creating Multiplayer Games with Godot 4.0
$49.99
Godot 4 Game Development Cookbook
$44.99
Total $ 139.97 Stars icon
Banner background image

Table of Contents

12 Chapters
Chapter 1: Exploring the Godot 4 Editor Chevron down icon Chevron up icon
Chapter 2: Transitioning to GDScript 2.0 Chevron down icon Chevron up icon
Chapter 3: 2D and 3D Rendering with Vulkan Chevron down icon Chevron up icon
Chapter 4: Practicing Physics and Handling Navigation in Godot 4 Chevron down icon Chevron up icon
Chapter 5: Playing with Shaders in Godot 4 Chevron down icon Chevron up icon
Chapter 6: Importing 3D Assets in Godot 4 Chevron down icon Chevron up icon
Chapter 7: Adding Sound and Music to Your Game Chevron down icon Chevron up icon
Chapter 8: Making 2D Games Easier with TileSet and TileMap Chevron down icon Chevron up icon
Chapter 9: Achieving Better Animations Using the New Animation Editor Chevron down icon Chevron up icon
Chapter 10: Exploring New Multiplayer Features in Godot 4 Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1
(17 Ratings)
5 star 41.2%
4 star 35.3%
3 star 11.8%
2 star 11.8%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




AsasinoManik Jul 01, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I haven't completed the whole book yet, but I liked the format and examples. Its a huge book a lot of content. Keep it up.
Amazon Verified review Amazon
Asaad Al-Barwani Jun 11, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book covers many of the 4.0 update's changes to the engine, going into detail for both beginners to the engine and experienced developers who have used previous versions of the engine. It introduces many of the versions most significant features, including a dedicated chapter on the new GDScript 2.0. The book feels a bit more geared towards the current developers to transition towards the new version, but a beginner could just as easily pick up the book and learn the basics through it as it explains itself every step of the way.The multiplayer chapter was especially useful to me, as I have no experience in net code or using multiplayer features, and the book walked me through it all exceptionally well.
Amazon Verified review Amazon
Xavier Jun 09, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
All the updates to Godot have been happening rather quickly, I appreciate straightforward written tutorials that allow me to learn by doing. This cookbook is an excellent reference with valuable scripts and scene setups for decals, volumetric fogs that look good, and all the basics of character bodies both 2d and 3d and more.
Amazon Verified review Amazon
Ajo S S Jun 10, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It is really helpful for people who are trying to get into Game Development using the latest version of Godot Engine.
Amazon Verified review Amazon
Jaleen Michai Bowens-Kelly Jun 12, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
After going through the contents of this book I can say that if you are a Godot developer from any skill level and background you might gain some value from this book. The book is loaded with examples to follow and learn from, how to structure certain work flows and patterns, and additional information on features you might not heard about. In general, if you want a project oriented guide for learning the changes to Godot 4 or a new user of Godot then this book I would recommend.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela