Godot Version
4.22
Question
Hey there,
I’m quite new to using Godot and wanted to share a problem and my solution with you in the hope of getting feedback so I can learn from it.
Take the following root structure in mind:
- game
- pausable
- pinklin(player)
- pause_menu
- pausable
When I display the pause_menu I want it display itself at the player’s posistion.
I ended doing the following:
When the pause menu is triggerd (pressing esc) I’m sending the signal ‘gamePaused’ from the pause_menu to pinklin. In pinklin there is now a func _on_pause_menu_game_paused. In there I get the player position and send a new signal ‘playerPos’ with the posistion added as a vector assigned to a variable player_position. To the pause_menu. Where in turn I get the new func _on_pinklin_player_pos wich sets the position of the pause_menu to the player_position.
In code:
pause_menu script:
signal gamePaused
func _input(event):
if event.is_action_pressed("pause"):
gamePaused.emit()
func _on_pinklin_player_pos(player_position):
var pos = Vector2(player_position)
pos.y -= 35
self.position = pos
pinklin script:
signal playerPos
func _on_pause_menu_game_paused():
var player_position: Vector2 = self.get_global_position()
playerPos.emit(player_position)
Im very eager to hear what you guys think about how I handeld this and what can be done better!