Changing bridge zindex and body set layer and mask from bridge process function to each bridge area on_body_entered and on_body_exited. This change optimize code avoiding to set zindex of bridge and body layers and mask each frame. The script bridge is not necessary anymore.

This commit is contained in:
2025-06-21 21:11:11 -03:00
parent 724df1b070
commit 2490ca1e37
5 changed files with 29 additions and 80 deletions

View File

@@ -1,23 +1,19 @@
extends Area2D
class_name BellowBridgeArea
var is_character_bellow_bridge: bool = false
var character_body: Node2D = null
func _on_body_entered(_body: Node2D) -> void:
self._set_character_body_bellow_bridge(_body, true)
if _body is BaseCharacter:
var bridge: TileMapLayer = self.get_parent()
bridge.z_index = 2
_body.set_collision_layer_value(4, false)
_body.set_collision_mask_value(4, false)
print("entering bellow bridge")
func _on_body_exited(_body: Node2D) -> void:
self._set_character_body_bellow_bridge(_body, false)
func _set_character_body_bellow_bridge(_body: Node2D, _state: bool) -> void:
if _body is BaseCharacter:
self.is_character_bellow_bridge = _state
self.character_body = _body
print("bellow bridge: " + str(_state))
func get_character_body_bellow_bridge() -> bool:
return self.is_character_bellow_bridge
func get_body() -> Node2D:
return self.character_body
var bridge: TileMapLayer = self.get_parent()
bridge.z_index = 0
_body.set_collision_layer_value(4, true)
_body.set_collision_mask_value(4, true)
print("exiting bellow bridge")