Browse Source

:truck: Manage brick color from a dedicated node

DricomDragon 3 years ago
parent
commit
e53671a5a4

+ 6 - 4
godot/component/entity/brick/Brick.tscn

@@ -2,7 +2,7 @@
 
 [ext_resource path="res://component/entity/brick/color_brik.png" type="Texture" id=1]
 [ext_resource path="res://component/entity/brick/Brick.gd" type="Script" id=2]
-[ext_resource path="res://component/entity/brick/BrickMainSprite.gd" type="Script" id=3]
+[ext_resource path="res://component/entity/brick/BrickMainColor.gd" type="Script" id=3]
 [ext_resource path="res://component/entity/brick/BrickLifeDisplay.gd" type="Script" id=4]
 [ext_resource path="res://component/entity/brick/common_brick.png" type="Texture" id=5]
 
@@ -18,10 +18,12 @@ script = ExtResource( 2 )
 texture = ExtResource( 5 )
 centered = false
 
-[node name="ColorSprite" type="Sprite" parent="."]
+[node name="MainColor" type="Node2D" parent="."]
+script = ExtResource( 3 )
+
+[node name="ColorSprite" type="Sprite" parent="MainColor"]
 texture = ExtResource( 1 )
 centered = false
-script = ExtResource( 3 )
 
 [node name="Shape" type="CollisionShape2D" parent="."]
 position = Vector2( 20, 10 )
@@ -29,5 +31,5 @@ shape = SubResource( 1 )
 
 [node name="LifeDisplay" type="Node2D" parent="."]
 script = ExtResource( 4 )
+[connection signal="life_changed" from="." to="MainColor" method="_on_Brick_life_changed"]
 [connection signal="life_changed" from="." to="LifeDisplay" method="_on_Brick_life_changed"]
-[connection signal="life_changed" from="." to="ColorSprite" method="_on_Brick_life_changed"]

+ 2 - 2
godot/component/entity/brick/BrickMainSprite.gd

@@ -1,5 +1,5 @@
-class_name BrickMainSprite
-extends Sprite
+class_name BrickMainColor
+extends Node2D
 
 
 const ColorUtil = preload("res://utility/ColorUtil.gd")

+ 4 - 4
godot/project.godot

@@ -24,10 +24,10 @@ _global_script_classes=[ {
 "language": "GDScript",
 "path": "res://component/entity/brick/BrickLifeDisplay.gd"
 }, {
-"base": "Sprite",
-"class": "BrickMainSprite",
+"base": "Reference",
+"class": "BrickMainColor",
 "language": "GDScript",
-"path": "res://component/entity/brick/BrickMainSprite.gd"
+"path": "res://component/entity/brick/BrickMainColor.gd"
 }, {
 "base": "Area2D",
 "class": "Catcher",
@@ -78,7 +78,7 @@ _global_script_class_icons={
 "Ball": "",
 "Brick": "",
 "BrickLifeDisplay": "",
-"BrickMainSprite": "",
+"BrickMainColor": "",
 "Catcher": "",
 "ColorUtil": "",
 "DeadLine": "",