feat: properly scale instantiated dragons
This commit is contained in:
parent
a169e953c3
commit
09586aaa5e
5 changed files with 12 additions and 5 deletions
|
@ -10,6 +10,7 @@ size = Vector2(128, 128)
|
||||||
script = ExtResource("1_jccds")
|
script = ExtResource("1_jccds")
|
||||||
|
|
||||||
[node name="Dragon" parent="." instance=ExtResource("2_l1h0r")]
|
[node name="Dragon" parent="." instance=ExtResource("2_l1h0r")]
|
||||||
|
position = Vector2(-64, -64)
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2(0, 1)
|
position = Vector2(0, 1)
|
||||||
|
|
|
@ -7,3 +7,4 @@
|
||||||
[node name="Sprite" type="Sprite2D" parent="."]
|
[node name="Sprite" type="Sprite2D" parent="."]
|
||||||
position = Vector2(0, 1)
|
position = Vector2(0, 1)
|
||||||
texture = ExtResource("1_ixu8j")
|
texture = ExtResource("1_ixu8j")
|
||||||
|
offset = Vector2(64, 64)
|
||||||
|
|
|
@ -2,6 +2,7 @@ extends Window
|
||||||
class_name Dragon
|
class_name Dragon
|
||||||
|
|
||||||
@export var dragon_speed: float = 20.0
|
@export var dragon_speed: float = 20.0
|
||||||
|
@export var dragon: Node2D
|
||||||
|
|
||||||
@onready var _actual_position: Vector2 = position
|
@onready var _actual_position: Vector2 = position
|
||||||
var main_window_rect: Rect2i
|
var main_window_rect: Rect2i
|
||||||
|
@ -63,3 +64,8 @@ func _pick_random_screen_position() -> void:
|
||||||
)
|
)
|
||||||
|
|
||||||
_target_pos = random_pos
|
_target_pos = random_pos
|
||||||
|
|
||||||
|
|
||||||
|
func set_scale(scale: float) -> void:
|
||||||
|
size = Vector2i(size.x * scale, size.y * scale)
|
||||||
|
dragon.scale = Vector2(scale, scale)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
[ext_resource type="Script" uid="uid://ch7d3wo8ucskb" path="res://scenes/window/draggable.gd" id="2_2r6si"]
|
[ext_resource type="Script" uid="uid://ch7d3wo8ucskb" path="res://scenes/window/draggable.gd" id="2_2r6si"]
|
||||||
[ext_resource type="PackedScene" uid="uid://baa8gpicw2yg0" path="res://scenes/dragons/dragon_sprite.tscn" id="3_ctdir"]
|
[ext_resource type="PackedScene" uid="uid://baa8gpicw2yg0" path="res://scenes/dragons/dragon_sprite.tscn" id="3_ctdir"]
|
||||||
|
|
||||||
[node name="DragonPopup" type="Window"]
|
[node name="DragonPopup" type="Window" node_paths=PackedStringArray("dragon")]
|
||||||
disable_3d = true
|
disable_3d = true
|
||||||
transparent_bg = true
|
transparent_bg = true
|
||||||
size = Vector2i(128, 128)
|
size = Vector2i(128, 128)
|
||||||
|
@ -13,6 +13,7 @@ borderless = true
|
||||||
transparent = true
|
transparent = true
|
||||||
script = ExtResource("1_ctdir")
|
script = ExtResource("1_ctdir")
|
||||||
dragon_speed = 100.0
|
dragon_speed = 100.0
|
||||||
|
dragon = NodePath("Dragon")
|
||||||
|
|
||||||
[node name="DragDropDetector" type="Control" parent="."]
|
[node name="DragDropDetector" type="Control" parent="."]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
|
@ -22,4 +23,3 @@ offset_bottom = 40.0
|
||||||
script = ExtResource("2_2r6si")
|
script = ExtResource("2_2r6si")
|
||||||
|
|
||||||
[node name="Dragon" parent="." instance=ExtResource("3_ctdir")]
|
[node name="Dragon" parent="." instance=ExtResource("3_ctdir")]
|
||||||
position = Vector2(64, 64)
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ func _calculate_relative_position(position: Vector2) -> Vector2i:
|
||||||
|
|
||||||
|
|
||||||
func _instantiate_dragon(relative_position: Vector2i) -> Node:
|
func _instantiate_dragon(relative_position: Vector2i) -> Node:
|
||||||
var dragon: Window = _dragon_template.instantiate()
|
var dragon: Dragon = _dragon_template.instantiate()
|
||||||
|
|
||||||
var window_position: Vector2i = DisplayServer.window_get_position()
|
var window_position: Vector2i = DisplayServer.window_get_position()
|
||||||
var window_size: Vector2i = DisplayServer.window_get_size()
|
var window_size: Vector2i = DisplayServer.window_get_size()
|
||||||
|
@ -36,8 +36,7 @@ func _instantiate_dragon(relative_position: Vector2i) -> Node:
|
||||||
dragon.position = window_position + relative_position - dragon.size / 2
|
dragon.position = window_position + relative_position - dragon.size / 2
|
||||||
|
|
||||||
var size: float = _calculate_window_scale().y
|
var size: float = _calculate_window_scale().y
|
||||||
dragon.size = Vector2i(dragon.size.x * size, dragon.size.y * size)
|
dragon.set_scale(size)
|
||||||
dragon.content_scale_factor = 0.5
|
|
||||||
dragon.main_window_rect = Rect2i(window_position, window_size)
|
dragon.main_window_rect = Rect2i(window_position, window_size)
|
||||||
dragon.show()
|
dragon.show()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue