-- 更新 Shield 逻辑 local UpdateShield = function(delta_ms) -- 更新角色动画 timer_shield_animation = timer_shield_animation + delta_ms if timer_shield_animation >= interval_shield_animation then idx_texture_shield = idx_texture_shield + 1 if idx_texture_shield > #texture_shield_list then idx_texture_shield = 1 end timer_shield_animation = 0 end -- 更新角色位置 if is_moving then location_shield = Lerp(location_shield, dst_location_shield, speed_player * delta_ms) if location_shield:sub(dst_location_shield):size() <= 1then timer_next_shadow, is_moving = 0, false end end end
-- 更新 FlushEffect 逻辑 local UpdateFlushEffect = function(delta_ms) -- 更新残影淡出逻辑 for _, shadow inipairs(shadow_list) do shadow.alpha = shadow.alpha - delta_ms / interval_shadow_fade_out * (alpha_shadow_init / 1.0) if shadow.alpha < 0then shadow.alpha = 0end end -- 更新残影颜色逻辑 timer_switch_color = timer_switch_color + delta_ms if timer_switch_color >= interval_switch_color then idx_color_list = idx_color_list + 1 if idx_color_list > #color_list then idx_color_list = 1 end timer_switch_color = 0 end -- 更新残影新增逻辑 ifnot is_moving thenreturnend timer_next_shadow = timer_next_shadow + delta_ms if timer_next_shadow >= interval_next_shadow then table.insert(shadow_list, { location = OpenGL.Vec2(location_shield), texture = texture_shield_list[idx_texture_shield], color = color_list[idx_color_list], alpha = alpha_shadow_init }) timer_next_shadow = 0 end end
冲刺特效的实现逻辑相对简单,依托于引擎的话可以使用粒子系统进行实现,且性能会更佳。
看一下在 EtherTK 中的实现效果:
最后贴一下万能的 Lerp 函数的实现,用来处理摄像机跟踪或滑铲效果极佳:
1 2 3 4 5 6
-- 二维向量插值 local Lerp = function(vec1, vec2, dist) local vec_dir = vec2:sub(vec1) dist = math.min(dist, vec_dir:size()) return OpenGL.Vec2(vec1:add(vec_dir:normalize():mul(dist))) end