kidscancode / godot_recipes

Lessons, tutorials, and guides for game development using the Godot game engine.
MIT License
240 stars 37 forks source link

Issues in "Your First 2D Game: 09 UI and Score" #128

Closed MoshiBin closed 1 year ago

MoshiBin commented 1 year ago

Enemy bullet scene

UI and Score

1) It is initially unclear if ShieldBar is supposed to be its own scene (like the score counter) or part of the UI scene - consider adding the UI scene tree to help the reader follow:

image

2) In the Score Counter, after duplicating the Digit0 TextureRect, the function display_digits changes all the textures at once instead of changing only the required digits. I solved this by doing Texture -> Make Unique on each TextureRect.

3) In the Score Counter script, there are two typos: a. It uses for i in 8 instead of for i in range(8). b. It should actually loop on range(10) since there are 10 digits.

4) Player shield also refers to ship.gd instead of player.gd

5) The UI function update_shield never gets called. This is not trivial to me as it's the first time I'm connecting signals between unrelated scenes - am I supposed to do this via Main?

cbscribe commented 1 year ago

Thanks for the comments. A few notes:

  1. It is initially unclear if ShieldBar is supposed to be its own scene (like the score counter) or part of the UI scene - consider adding the UI scene tree to help the reader follow:

Good suggestion

  1. In the Score Counter, after duplicating the Digit0 TextureRect, the function display_digits changes all the textures at once instead of changing only the required digits. I solved this by doing Texture -> Make Unique on each TextureRect.

That's unnecessary. They all have the same texture. Only the region property is changed.

  1. In the Score Counter script, there are two typos:

Neither of these are typos.

a. It uses for i in 8 instead of for i in range(8).

This is valid GDScript. range() is not needed here.

b. It should actually loop on range(10) since there are 10 digits.

The ScoreCounter is an 8 digit number: "Select the Digit0 node and press Ctrl-D 7 times to create duplicates of the node. ... Then, display_digits() will format the number to an 8 digit number (for example, 258 would become "00000258"). "

  1. Player shield also refers to ship.gd instead of player.gd

This will be corrected.

The UI function update_shield never gets called. This is not trivial to me as it's the first time I'm connecting signals between unrelated scenes - am I supposed to do this via Main?

Yes, in Main. Will add some additional text to clarify.

MoshiBin commented 1 year ago

Doh - sorry about the typo comment, my bad. I misread the instructions and duplicated for a total of 10 digits instead of 8. It's good to know about the for loop syntax, thank you for that.

However, I do see that issue with duplicating without making unique. To test it now, I've made Digit0-6 unique, and Digit7 is a duplicate of Digit6; now both Digit6 and Digit7 update to the same number every time. I.e. the score flips between 00000055 and 00000000 until it reaches 100, which correctly changes the relevant digit to 1 but the last two digits still flip between 00 and 55. When all digits were duplicates, it flipped between 55555555 and 00000000. I can share the project if you'd like. (Edit: Uploaded to https://github.com/MoshiBin/ShmupDemo)

Now I'm going over the section "Starting and Ending the Game", and it references a function called new_game() which I couldn't find anywhere. I'm guessing it should either look something like:

func new_game():
    score = 0
    $CanvasLayer/UI.update_score(score)
    $Player.start()
    spawn_enemies()

or just be changed to spawn_enemies(), depends on whether or not the ship's position should reset when starting a game. I also changed player.gd to hide() in _ready(), and in start() I called show() and set shield = max_shield so the shield bar will update when the game restarts.

GreenGuy5294 commented 1 year ago

That's unnecessary. They all have the same texture. Only the region property is changed.

I am very much a beginner to Godot, but following through the tutorial, applying "Make Unique" to each texture was indeed necessary, otherwise all the digits update to the last digit set, which is the one's place.

AlexandreBrach commented 1 year ago

I meet the same behavior : the texture is a reference, so changing the value of its region property affects any digits the same way, it explains the "Make Unique" workaround.

cbscribe commented 1 year ago

I've made a complete pass through the written tutorial to fix many of these inconsistencies. I'm going to close this issue, because I think I got them all. If you still see something missing/incorrect, please open a new issue for it.