Files
mortal-maze-the-game/world/backgrounds/painted_hall.gd

59 lines
1.9 KiB
GDScript

@tool
extends TextureRect
class_name PaintedHall
## Mural con profundidad real dentro de los limites de una sala. La camara
## recorre una pintura grande lentamente; columnas y plataformas siguen al mundo.
## No se estira una ilustracion sobre toda la altura de una torre.
const HALL_SHADER: Shader = preload("res://world/backgrounds/painted_hall.gdshader")
@export var parallax_ratio: Vector2 = Vector2(0.24, 0.18):
set(value):
parallax_ratio = value
_update_layout()
@export var composition_offset: Vector2 = Vector2(0.0, 160.0):
set(value):
composition_offset = value
_update_layout()
@export_range(0.25, 2.0, 0.05) var art_scale: float = 1.0:
set(value):
art_scale = maxf(value, 0.25)
_update_layout()
var _hall_material: ShaderMaterial
var _last_camera_local: Vector2 = Vector2.INF
func _ready() -> void:
mouse_filter = Control.MOUSE_FILTER_IGNORE
texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
expand_mode = TextureRect.EXPAND_IGNORE_SIZE
_hall_material = ShaderMaterial.new()
_hall_material.shader = HALL_SHADER
material = _hall_material
resized.connect(_update_layout)
_update_layout()
if Engine.is_editor_hint():
_hall_material.set_shader_parameter("camera_local", size * 0.5)
set_process(false)
func _update_layout() -> void:
if _hall_material == null:
return
_hall_material.set_shader_parameter("panel_size", size)
_hall_material.set_shader_parameter("parallax_ratio", parallax_ratio)
_hall_material.set_shader_parameter("composition_offset", composition_offset)
_hall_material.set_shader_parameter("art_scale", art_scale)
func _process(_delta: float) -> void:
var camera: Camera2D = get_viewport().get_camera_2d()
if camera == null:
return
var local_position: Vector2 = get_global_transform().affine_inverse() * camera.get_screen_center_position()
if local_position.is_equal_approx(_last_camera_local):
return
_last_camera_local = local_position
_hall_material.set_shader_parameter("camera_local", local_position)