Add slow skybox rotation to 3D scene and 2D scene backgrounds
3D (game_screen): _process increments env.sky_rotation.y at 0.026 rad/s (~4 min per full revolution) — works for all sky types (panoramic, animated panoramic, cubemap shader) via Godot's built-in EYEDIR transform. 2D (ContentCache): apply_scene_background attaches a canvas_item ShaderMaterial to the background TextureRect that horizontally scrolls UV.x using the built-in TIME uniform at 0.004 UV/s (matching the ~4 min cycle) — no GDScript tick needed. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -203,6 +203,7 @@ func load_texture_async(url: String, callback: Callable) -> void:
|
||||
|
||||
## Hides the first direct-child ColorRect of `parent` and injects a full-rect
|
||||
## TextureRect (from a random active skybox) as the new first child.
|
||||
## The texture slowly scrolls horizontally to match the 3D sky rotation feel.
|
||||
## Call from _ready() in any 2D scene that has a solid-color background.
|
||||
func apply_scene_background(parent: Control) -> void:
|
||||
var skybox := get_random_skybox()
|
||||
@@ -224,6 +225,12 @@ func apply_scene_background(parent: Control) -> void:
|
||||
tr.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
|
||||
tr.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
tr.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
# Slowly scroll UV horizontally — same ~4-min revolution as the 3D sky rotation.
|
||||
var shader := Shader.new()
|
||||
shader.code = "shader_type canvas_item;\nvoid fragment() {\n\tvec2 uv = UV;\n\tuv.x = fract(uv.x + TIME * 0.004);\n\tCOLOR = texture(TEXTURE, uv);\n}\n"
|
||||
var mat := ShaderMaterial.new()
|
||||
mat.shader = shader
|
||||
tr.material = mat
|
||||
parent.add_child(tr)
|
||||
parent.move_child(tr, 0))
|
||||
|
||||
|
||||
@@ -158,6 +158,7 @@ var _anim_players : Dictionary = {} # instanceId → AnimationPlayer (null if
|
||||
var _unit_def_ids : Dictionary = {} # instanceId → card definition ID string
|
||||
|
||||
# ── Skybox state ───────────────────────────────────────────────────────────────
|
||||
const SKY_ROTATION_SPEED := 0.026 # rad/sec — ~4 min per full revolution
|
||||
var _skybox_sky : Sky = null # the Sky object created in _setup_environment
|
||||
var _skybox_frames : Array = [] # Array[ImageTexture] for animated skybox frames
|
||||
var _skybox_frame_idx : int = 0
|
||||
@@ -262,6 +263,12 @@ func _ready() -> void:
|
||||
Game.send_ready()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var env := $WorldEnvironment.environment
|
||||
if env != null:
|
||||
env.sky_rotation.y += delta * SKY_ROTATION_SPEED
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if _is_spectating:
|
||||
Game.stop_spectating()
|
||||
|
||||
Reference in New Issue
Block a user