Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class_name AnchorDetector2D
- extends Area2D
- signal anchor_detached
- signal anchor_updated(anchor)
- var current_anchor = null setget update_anchor
- var candidate_anchor = null
- func _ready():
- connect("anchor_updated", GameManager, "on_room_changed")
- func update_anchor(new):
- current_anchor = new
- new.room_entered()
- emit_signal("anchor_updated", new)
- func _on_AnchorDetector2d_area_entered(area: Anchor2D) -> void:
- area.room_pre_entered() #Для подгрузки комнаты в память
- if current_anchor == null:
- update_anchor(area)
- else:
- candidate_anchor = area
- func _on_AnchorDetector2d_area_exited(area: Anchor2D) -> void:
- if candidate_anchor == null:
- current_anchor = null
- emit_signal("anchor_detached")
- else:
- if area == current_anchor:
- update_anchor(candidate_anchor)
- area.room_exited()
- candidate_anchor = null
Advertisement
Add Comment
Please, Sign In to add comment