Go back to the Font settings, where we created the font, and change the size. Luckily, since we are using our own font, we can change the size / clarity etc. In the text section of the Label, add: My Jumpy Game In the Inspector, go to Theme overrides, choose Fonts, and add a new Dynamic font:įor this project, Im using IndieFlower font by Google. Creating the Start and End ScreensĬreate a new scene of type "User Interface", adn add a child ColorRect:įor the ColorRect, change the color (to whatever you want) and size to your window size (1024圆00 in our case):Īdd a new Label as a child to the top start node. We don't have the end screen (when the player loses all lives), we need to create one. Get_parent().get_node("hud/lives_left").text = str(ayer_lives) TOTAL_COINS=get_parent().get_node("coins").get_child_count() Update the _ready and die function: func _ready(): Now go to Project- > Project Settings -> Autoload, and add our script: In the scripts window (File->New Script), create a new script called global.gd: extends Node Using the Autoload (singleton) pattern to remember player state The way to do that in Godot is to use the Singleton pattern We need a way to remember the lives left variable between games. We could just create a new variable, with: var lives_left = 3īut the problem with that is: Every time the level reloads, like when the player dies, lives_left will be reset to 3. Now we need to update the lives left variable. Get_tree().change_scene("res://level1.tscn") Let's give the player 3 lives, after which the game ends.Ĭopy the coins found hud code and add lives left:Ĭreate a new function die(), to be called everywhere we were manually changing the scene to level 1 (like when we touched the spikes and died): func die(): Let's add a game start and game over scene. We get the node "hud/coins_found", and update its text to show the coins found / total coins. Get_parent().get_node("hud/coins_found").text = str(coins_found) + " / " + str(TOTAL_COINS) Update the code: func _on_coin_body_entered(_body): There are multiple ways to do it, the most ideal is to use signals I will use the lazy approach and directly change the text on the coins_found label. You will note it remains at the same place on the screen. Try the game, move the coins found box if you want: For the 1st one, add the text Coins Found, and click "Uppercase" option below it Reduce it till our box becomes see thru:īack to our hud: add 2 Label nodes. The only thing we want to change is the 'A' field, which stands for Alpha. Why flat? As we dont need a special texture file for it ( )Ĭlick on the new stylebox you just created and select BG color: With Panel selected, choose New Style box on the right and choose Flat: We want to make it see thru, so it doesn't interferere with the game. In this post, we will prety-fy our game a little– add game start and over screens, add a heads up display to show how many coins we have etc.Ī Hud is a window that remains in a fixed position on the screen, and can be used to show such things as the number of lives, coins etc.Ī CanvasLayer can be used for drawing to the screen it will be separate from the game logic, so it won't be affected when you move the player etc.Īdd a CanvasLayer, rename it to hud, and add a child Panel:Īs you can see, the Panel is black and overwriting our screen.
0 Comments
Leave a Reply. |