RapidGameFramework
Reusable Godot managers for data-driven small games
Loading...
Searching...
No Matches
sprite_animation_rect.gd
Go to the documentation of this file.
1extends TextureRect
2
3
6
7var frames := []
8var fps := 8.0
9var loop := true
10var playing := true
11var elapsed := 0.0
12var current_frame := -1
13
14
15
16func configure(next_frames:Array, options:Dictionary = {}) -> void:
17 frames = next_frames.duplicate()
18 fps = max(0.1, float(options.get("fps", 8.0)))
19 loop = bool(options.get("loop", true))
20 playing = bool(options.get("autoplay", true))
21 elapsed = float(options.get("offset_seconds", 0.0))
22 stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
23 expand_mode = TextureRect.EXPAND_IGNORE_SIZE
24 mouse_filter = Control.MOUSE_FILTER_IGNORE
25 _update_frame()
26
27
28func play() -> void:
29 playing = true
30
31
32func stop() -> void:
33 playing = false
34
35
36func _process(delta:float) -> void:
37 if not playing or frames.size() <= 1:
38 return
39 elapsed += delta
40 _update_frame()
41
42
43func _update_frame() -> void:
44 if frames.is_empty():
45 texture = null
46 current_frame = -1
47 return
48 var frame = int(floor(elapsed * fps))
49 if loop:
50 frame = frame % frames.size()
51 else:
52 frame = min(frame, frames.size() - 1)
53 if frame == current_frame:
54 return
55 current_frame = frame
56 texture = frames[current_frame]