Home > Articles

  • Print
  • + Share This
This chapter is from the book

Q&A

Q. Why do we even need to queue_free everything? Can’t we just hide nodes?

A. You could, of course, just do that. But then Godot has to keep all those objects in memory and possibly has to still do the _process() function on every object on every frame, even if we do not need them anymore. This can be very bad for performance and memory consumption.

Q. Why do I get the same asteroid pattern every time I start the game?

A. Because Godot uses a default seed for its random number generator. If you want a different pattern each time the game starts, you can reseed the random number generator by placing the randomize() function into the _ready() function of the stage script (you may need to create a _ready() function first).

Q. Why do we connect the destroy and timeout signals in the stage script by code?

A. There is no particular reason other than to show that this is possible. You could connect them by using the editor. The score signals of the asteroids, however, cannot be connected by using the editor, because the asteroids do not exist in the stage scene until they are spawned in-game.

Q. What is the number 8 doing in the if-statement of the _process() functions in the asteroid and shot scripts?

A. The dimensions of the shot Sprite and the asteroid Sprite are both 16 x 16 pixels, respectively. If we ask for position.x >= SCREEN_WIDTH + 8, we mean that the x position of the Sprite should be greater than the screen width plus half its Sprite-width in pixels. As the Sprite position is normally its centerpoint, we mean, “Is the Sprite now out of our screen boundary?”

  • + Share This
  • 🔖 Save To Your Account