From 877f1e491b60b6061eb28d477a50036794993956 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Fri, 26 Jul 2024 23:04:04 +0930 Subject: [PATCH] Make worldmap event changes fade in instead of pop in --- shaders/worldmap_shader.gdshader | 4 ++-- test/worldmap_system.gd | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/shaders/worldmap_shader.gdshader b/shaders/worldmap_shader.gdshader index d3c76c1..be4c313 100644 --- a/shaders/worldmap_shader.gdshader +++ b/shaders/worldmap_shader.gdshader @@ -97,7 +97,7 @@ void fragment() { } // World 1 also has row #6 cols #12 and #13 swap every 5 frames at 60fps (12Hz) (world 2 portal) vec2 palette_uv = vec2(pal_col, pal_row); - COLOR = texture(palette, palette_uv); + COLOR.rgb = texture(palette, palette_uv).rgb; - COLOR.a = step(0.000001, color_idx16); // Branchless transparency + COLOR.a *= step(0.000001, color_idx16); // Branchless transparency } diff --git a/test/worldmap_system.gd b/test/worldmap_system.gd index 0863251..7ef0f11 100644 --- a/test/worldmap_system.gd +++ b/test/worldmap_system.gd @@ -11,6 +11,7 @@ var map_textures := [null, null, null, null, null] var map_regional_replacement_amounts := [0, 0, 0, 0, 0] var map_regional_replacement_lists := [[], [], [], [], []] var current_texture: Texture +var last_event_texture: Texture # For fading events in var minimap_mode := 0 var minimap_tween := 0.0 @@ -60,6 +61,7 @@ func _jump_to_regional_replacement(region) -> void: print_debug('Jumping to event position ', self.pos.x, self.pos.y) var delay_map_update: float = -1.0 +const MAX_DELAY_MAP_UPDATE = 1.0 func _perform_regional_replacement(amount: int) -> void: var map = MapLoader.worldmaps[current_map_id] var last_region @@ -67,7 +69,7 @@ func _perform_regional_replacement(amount: int) -> void: 0: map.blockmap = map.blockmap_original self.map_regional_replacement_amounts[current_map_id] = 0 - self.delay_map_update = 0.0001 + self.delay_map_update = 0.0 1: if self.map_regional_replacement_amounts[current_map_id] >= len(self.map_regional_replacement_lists[current_map_id]): return @@ -75,7 +77,8 @@ func _perform_regional_replacement(amount: int) -> void: map.apply_event_region_replacement(last_region) self._jump_to_regional_replacement(last_region) self.map_regional_replacement_amounts[current_map_id] += 1 - self.delay_map_update = 1.0 + self.last_event_texture = self.current_texture + self.delay_map_update = MAX_DELAY_MAP_UPDATE -1: if self.map_regional_replacement_amounts[current_map_id] < 1: return @@ -86,9 +89,9 @@ func _perform_regional_replacement(amount: int) -> void: last_region = self.map_regional_replacement_lists[current_map_id][i] map.apply_event_region_replacement(last_region) # self._jump_to_regional_replacement(last_region) - self.delay_map_update = 0.0001 - # self._create_worldmap_texture(current_map_id) - # self._set_map(current_map_id) # refresh shader etc. + self.delay_map_update = 0.0 + self._create_worldmap_texture(current_map_id) + self._set_map(current_map_id) # refresh shader etc. # Called when the node enters the scene tree for the first time. @@ -138,9 +141,6 @@ func _process(delta: float) -> void: # Hack to do a presentation of map region replacements with a nice before and after if self.delay_map_update > 0.000: self.delay_map_update -= delta - if self.delay_map_update <= 0.000: - self._create_worldmap_texture(current_map_id) - self._set_map(current_map_id) # refresh shader etc. update() @@ -155,6 +155,10 @@ func _draw() -> void: var uvpos := pos/256.0 var v_uvs := PoolVector2Array([uvpos+Vector2(-UV_W2, -UV_H2), uvpos+Vector2(UV_W2, -UV_H2), uvpos+Vector2(UV_W2, UV_H2), uvpos+Vector2(-UV_W2, UV_H2)]) draw_primitive(V_POINTS, V_COLORS, v_uvs, self.current_texture) + if self.delay_map_update > 0.0: + var alpha = self.delay_map_update / MAX_DELAY_MAP_UPDATE + var color = Color(1, 1, 1, alpha) + draw_primitive(V_POINTS, [color, color, color, color], v_uvs, self.last_event_texture) #draw_texture_rect_region(self.map_textures[0], Rect2(0, 0, 384, 240), Rect2(pos.x, pos.y, pos.x+VW, pos.y+VH), Color.white, false, null, false) func _input(event: InputEvent) -> void: