tile_map.gd 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. extends TileMapLayer
  2. # You can have multiple layers if you make this an array.
  3. var player_in_secret: bool = false
  4. var layer_alpha := 1.0
  5. func _ready() -> void:
  6. set_process(false)
  7. func _process(delta: float) -> void:
  8. if player_in_secret:
  9. if layer_alpha > 0.3:
  10. # Animate the layer transparency.
  11. layer_alpha = move_toward(layer_alpha, 0.3, delta)
  12. self_modulate = Color(1, 1, 1, layer_alpha)
  13. else:
  14. set_process(false)
  15. else:
  16. if layer_alpha < 1.0:
  17. layer_alpha = move_toward(layer_alpha, 1.0, delta)
  18. self_modulate = Color(1, 1, 1, layer_alpha)
  19. else:
  20. set_process(false)
  21. func _use_tile_data_runtime_update(_coords: Vector2i) -> bool:
  22. return true
  23. func _tile_data_runtime_update(_coords: Vector2i, tile_data: TileData) -> void:
  24. # Remove collision for secret layer.
  25. tile_data.set_collision_polygons_count(0, 0)
  26. func _on_secret_detector_body_entered(body: Node2D) -> void:
  27. if body is not CharacterBody2D:
  28. # Detect the player only.
  29. return
  30. player_in_secret = true
  31. set_process(true)
  32. func _on_secret_detector_body_exited(body: Node2D) -> void:
  33. if body is not CharacterBody2D:
  34. return
  35. player_in_secret = false
  36. set_process(true)