Additional resource tweaks.
This commit is contained in:
parent
2c2b23f0bb
commit
6c41810add
5 changed files with 36 additions and 7 deletions
|
|
@ -41,3 +41,21 @@ func _on_visible_on_screen_notifier_2d_screen_exited():
|
|||
func set_weapon_data(bullet_scene_param: PackedScene, shot_data_param: WeaponShot):
|
||||
bullet_scene = bullet_scene_param
|
||||
shot_data = shot_data_param
|
||||
|
||||
# Function to offset animation playback for staggered visual effect
|
||||
func set_animation_offset(offset: float) -> void:
|
||||
var sprite = $AnimatedSprite2D
|
||||
if sprite:
|
||||
var frames = sprite.sprite_frames
|
||||
if frames:
|
||||
var animation = sprite.animation
|
||||
var frame_count = frames.get_frame_count(animation)
|
||||
if frame_count > 0:
|
||||
# Calculate average frame duration from actual frame timings
|
||||
var total_duration = 0.0
|
||||
for i in range(frame_count):
|
||||
total_duration += frames.get_frame_duration(animation, i)
|
||||
var avg_frame_duration = total_duration / frame_count
|
||||
# Convert time offset to frame offset, wrap within animation length
|
||||
var frame_offset = fposmod(offset / avg_frame_duration, float(frame_count))
|
||||
sprite.frame = int(frame_offset)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue