@@ -6,6 +6,8 @@ const BlockDefinition = preload("res://addons/block_code/code_generation/block_d
6
6
const BlocksCatalog = preload ("res://addons/block_code/code_generation/blocks_catalog.gd" )
7
7
const Types = preload ("res://addons/block_code/types/types.gd" )
8
8
9
+ ## A texture can be provided for simple setup. If provided, the character will have a collision box
10
+ ## that matches the size of the texture.
9
11
@export var texture : Texture2D :
10
12
set = _set_texture
11
13
@@ -44,8 +46,28 @@ func _set_texture(new_texture):
44
46
45
47
46
48
func _texture_updated ():
49
+ if not texture :
50
+ if sprite :
51
+ sprite .queue_free ()
52
+ sprite = null
53
+ if collision :
54
+ collision .queue_free ()
55
+ collision = null
56
+ return
57
+
58
+ if not sprite :
59
+ sprite = Sprite2D .new ()
60
+ sprite .name = & "Sprite2D"
61
+ add_child (sprite )
62
+
63
+ if not collision :
64
+ collision = CollisionShape2D .new ()
65
+ collision .name = & "CollisionShape2D"
66
+ collision .shape = RectangleShape2D .new ()
67
+ add_child (collision )
68
+
47
69
sprite .texture = texture
48
- collision .shape .size = Vector2 ( 100 , 100 ) if texture == null else texture .get_size ()
70
+ collision .shape .size = texture .get_size ()
49
71
50
72
51
73
## Nodes in the "affected_by_gravity" group will receive gravity changes:
@@ -59,16 +81,6 @@ func _ready():
59
81
60
82
func simple_setup ():
61
83
add_to_group ("affected_by_gravity" , true )
62
-
63
- sprite = Sprite2D .new ()
64
- sprite .name = & "Sprite2D"
65
- add_child (sprite )
66
-
67
- collision = CollisionShape2D .new ()
68
- collision .name = & "CollisionShape2D"
69
- collision .shape = RectangleShape2D .new ()
70
- add_child (collision )
71
-
72
84
_texture_updated ()
73
85
74
86
0 commit comments