This isn’t possible out of the box yet, see this PR which implements it:
It is possible to script a custom implementation (which should work well enough when constrained to a single screen), still.
This isn’t possible out of the box yet, see this PR which implements it:
It is possible to script a custom implementation (which should work well enough when constrained to a single screen), still.
Ok, strange that its not supported out of the box. Feels pretty basic in my opinion.
Is it hard to make this?
I have character select screen scene with 3 text buttons.
I dont know. Not sure how to do it.
Any tutorial you can recommend?
I have another problem I want to solve:
When a character is out lives the character_select.tscn will now load. How do I disable the button for that character when he is out of lives (or dead). Creating another var in my Global.gd or in the character_select.tscn?
Also the game needs to remember which current level the player was on when that character died so it spawns one of the remaining characters to the same level when the player continues.
When all characters are dead I want to load a game over scene.
Any ideas on how to best set this up?
Thanks in advance
I would just check against a bool in a global. If true - then spawn in the button. If false - don’t spawn in. Set to false when the character dies.
To restart at the same stage, just set another global variable “stage_to_retry” or such to whatever stage you died on. Set it when you die. When selecting a character and continuing, load(stage_to_retry)
By the way, it seems like you are very early in development and it would make sense for you to switch to the most recent version before you have made more progress. The less progress you have, the less risk you will have to rework parts of the game.
Here is my current code for Global.gd:
extends Node
var selected_character
var character_array = ["res://character1.tscn", "res://character2.tscn", "res://character3.tscn", "res://character4.tscn"]
var coins = 0
var max_hearts = 3
var hearts = max_hearts
var max_lives = 3
var lives = max_lives
var hud
func lose_heart():
hearts -= 1
hud.load_hearts()
if hearts <= 0:
get_tree().reload_current_scene()
lose_life()
hearts = max_hearts
func lose_life():
lives -= 1
if lives <= 0:
get_tree().change_scene("res://character_select.tscn")
func add_coin():
coins += 1
Can I use the var selected_character or do I need to create a new one for the bool?
Current code for character_select.gd:
extends Control
func _ready():
pass
func _on_Character1Button_pressed():
Global.selected_character = load(Global.character_array[0])
Global.lives = Global.max_lives
get_tree().change_scene("res://level_1.tscn")
func _on_Character2Button_pressed():
Global.selected_character = load(Global.character_array[1])
Global.lives = Global.max_lives
get_tree().change_scene("res://level_1.tscn")
func _on_Character3Button_pressed():
Global.selected_character = load(Global.character_array[2])
Global.lives = Global.max_lives
get_tree().change_scene("res://level_1.tscn")
func _on_Character4Button_pressed():
Global.selected_character = load(Global.character_array[3])
Global.lives = Global.max_lives
get_tree().change_scene("res://level_1.tscn")
func _on_BackTextButton_pressed():
get_tree().change_scene("res://TitleScreen.tscn")
Code level_1.gd:
extends Node2D
func _ready():
var character = Global.selected_character
var instance = character.instance()
instance.position = $CharacterSpawnArea.position
get_tree().current_scene.add_child(instance)
#TitleMusic.stop()
# InGameMusic.play()
$CanvasLayer/Label/AnimationPlayer.play("textfade")
What do I call the bool in my Global.gd @baba ?
Like var character_alive = true
And and then set Global.character_alive = false when the character dies?
And if Global.character_alive = false then disable button ?
For example in ready.
If character1_dead == true: character1_button.disabled = true
or is it .enabled = true? I forgot. One of the two
If character2…
Etc
You can also change stylebox to show that ok now this button is broken or whatever.
Ok, so I need var character1_dead = true
character2_dead = false etc i my Global.gd
How do Global.gd knows which character has died?
This is the code for character1.gd when he gets hurt:
func ouch(var enemyposx):
Global.lose_heart()
#set_modulate(Color(1,0,0,0.7))
$AnimationPlayer.play("hurt")
velocity.y = JUMPFORCE * 0.5
if position.x < enemyposx:
velocity.x = -800
elif position.x > enemyposx:
velocity.x = 800
Input.action_release("ui_left")
Input.action_release("ui_right")
It will then run the Global.lose_heart()
and when the character dies:
func lose_life():
lives -= 1
if lives <= 0:
get_tree().change_scene("res://character_select.tscn")
So I´ll guess I need to put something in character1.gd when func lose_life() runs in Global.gd?
Like maybe: if Global.lives <=0:
Global.character1_dead = true
Would that work?
Or maybe remove the line “if lives <= 0:
get_tree().change_scene(“res://character_select.tscn”)” from Global.gd and add: “if Global.lives <= 0:
Global.character1_dead = true
get_tree().change_scene(“res://character_select.tscn”)” somewhere in the character1.gd script? Under func_ready or under func ouch?
Edit: I tried this now and it seems to work! ![]()
How do I make the player to be sent to the game over screen when all characters are dead?
Something like this maybe:
If character1_dead, character2_dead, character3_dead, character4_dead == true:
get_tree().change_scene(“res://game_over.tscn”)
Try to solve it by yourself for a bit. If you cant solve it i will help you.
Yes, I just solved it myself ![]()
To send the player to the Game over scene I just added this in the character_select.gd:
If character1_dead and character2_dead and character3_dead and character4_dead == true:
get_tree().change_scene(“res://game_over.tscn”)
Not sure if its the right way to do it but it seems to work fine!
Good! I think there is no real right or wrong way here. The best way to do it is to do it in a way that does the job and that you will easily be able to understand and make changes to in the future. If you need to revisit the code to include for example a fifth character in three months, your solution here is a lot better than a “better” solution that you would kind of struggle to understand and work with. Especially as this is a piece of code that seemingly will at most run a handful of times per game!
Thanks @baba!
I have now successfully made a working character select screen for 2 players also with the help of Googles AI assistent. ![]()
I also have a working HUD with heart and lives counter for P2.
For the multiplayer mode I disabled godots native focus for UI buttons and using an own code with P1> and P2> markers.
If anyone would be interested in the code for the multiplayer selection screen just tell me.