26 lines
749 B
GDScript
26 lines
749 B
GDScript
extends Control
|
|
|
|
var ship_sprite: Sprite2D
|
|
|
|
func _ready() -> void:
|
|
if GameState.selected_ship_path.is_empty() or not ResourceLoader.exists(GameState.selected_ship_path):
|
|
push_warning("Nie wybrano statku do nowej gry.")
|
|
return
|
|
|
|
var ship_texture := load(GameState.selected_ship_path) as Texture2D
|
|
if ship_texture == null:
|
|
push_warning("Nie udało się wczytać wybranego statku.")
|
|
return
|
|
|
|
ship_sprite = Sprite2D.new()
|
|
ship_sprite.name = "PlayerShip"
|
|
ship_sprite.texture = ship_texture
|
|
add_child(ship_sprite)
|
|
_update_game_layout()
|
|
get_viewport().size_changed.connect(_update_game_layout)
|
|
|
|
func _update_game_layout() -> void:
|
|
if ship_sprite:
|
|
var viewport_size := get_viewport_rect().size
|
|
ship_sprite.position = viewport_size * 0.5
|