8000 Merge pull request #216 from endlessm/no-imposed-collision · endlessm/godot-block-coding@1fd3db8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1fd3db8

Browse files
authored
Merge pull request #216 from endlessm/no-imposed-collision
SimpleCharacter: Don't impose a collision shape
2 parents 67def96 + b3c4890 commit 1fd3db8

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

addons/block_code/simple_nodes/simple_character/simple_character.gd

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const BlockDefinition = preload("res://addons/block_code/code_generation/block_d
66
const BlocksCatalog = preload("res://addons/block_code/code_generation/blocks_catalog.gd")
77
const Types = preload("res://addons/block_code/types/types.gd")
88

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.
911
@export var texture: Texture2D:
1012
set = _set_texture
1113

@@ -44,8 +46,28 @@ func _set_texture(new_texture):
4446

4547

4648
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+
4769
sprite.texture = texture
48-
collision.shape.size = Vector2(100, 100) if texture == null else texture.get_size()
70+
collision.shape.size = texture.get_size()
4971

5072

5173
## Nodes in the "affected_by_gravity" group will receive gravity changes:
@@ -59,16 +81,6 @@ func _ready():
5981

6082
func simple_setup():
6183
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-
7284
_texture_updated()
7385

7486

0 commit comments

Comments
 (0)
0