Skip to content

Commit 3d2ad06

Browse files
authored
Merge pull request #1762 from endlessm/wjt/randomframespritebehavior-randomize-frame-progress-too
RandomFrameSpriteBehavior: Randomize frame progress too
2 parents 67fe109 + c629461 commit 3d2ad06

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

scenes/game_logic/sprite_behaviors/random_frame_sprite_behavior.gd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ extends BaseSpriteBehavior
1010

1111
func _ready() -> void:
1212
var frames_length: int = sprite.sprite_frames.get_frame_count(sprite.animation)
13-
sprite.frame = randi_range(0, frames_length)
13+
# TODO: weight the choice of frame by the relative lengths of frames.
14+
# i.e. if an animation has one frame lasting 800ms, and four frames lasting 100ms each,
15+
# we should be 8× more likely to pick the 800ms frame than each of the other 4.
16+
sprite.set_frame_and_progress(randi_range(0, frames_length), randf())
1417

1518

1619
func _notification(what: int) -> void:
1720
match what:
1821
NOTIFICATION_EDITOR_PRE_SAVE:
19-
sprite.frame_progress = 0
22+
sprite.frame = 0

0 commit comments

Comments
 (0)