optimize energy scene and code
This commit is contained in:
parent
9e11c80f4f
commit
c188688bcf
@ -4,11 +4,12 @@ using System;
|
||||
public class Energy : Area2D
|
||||
{
|
||||
private Event _eventBus;
|
||||
private AnimatedSprite _sprite;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_eventBus = GetNode<Event>("/root/Event");
|
||||
GetNode<AnimatedSprite>("AnimatedSprite").Play();
|
||||
_sprite = GetNode<AnimatedSprite>("AnimatedSprite");
|
||||
}
|
||||
|
||||
public void OnEnergyBodyEntered(Node body)
|
||||
@ -22,4 +23,14 @@ public class Energy : Area2D
|
||||
}
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
public void OnVisibilityNotifier2DScreenEntered()
|
||||
{
|
||||
_sprite.Play();
|
||||
}
|
||||
|
||||
public void OnVisibilityNotifier2DScreenExited()
|
||||
{
|
||||
_sprite.Stop();
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ animations = [ {
|
||||
} ]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=4]
|
||||
extents = Vector2( 2.5, 6.5 )
|
||||
extents = Vector2( 2.5, 5.75 )
|
||||
|
||||
[node name="Energy" type="Area2D"]
|
||||
collision_layer = 8
|
||||
@ -29,10 +29,16 @@ script = ExtResource( 2 )
|
||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||
frames = SubResource( 3 )
|
||||
animation = "glow"
|
||||
centered = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2( -0.5, -0.5 )
|
||||
position = Vector2( 7.5, 7.25 )
|
||||
shape = SubResource( 4 )
|
||||
|
||||
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
|
||||
position = Vector2( 14, 11 )
|
||||
rect = Rect2( -10, -10, 7, 13 )
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="OnEnergyBodyEntered"]
|
||||
[connection signal="screen_entered" from="VisibilityNotifier2D" to="." method="OnVisibilityNotifier2DScreenEntered"]
|
||||
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="OnVisibilityNotifier2DScreenExited"]
|
||||
|
Loading…
Reference in New Issue
Block a user