18 lines
531 B
GDScript
18 lines
531 B
GDScript
class_name AnimationStrip
|
|
extends Resource
|
|
|
|
|
|
@export var texture: Texture
|
|
@export var frames: int = 1
|
|
@export var fps: float = 1.0
|
|
|
|
|
|
func draw(canvas_item: CanvasItem, time: float, modulate: Color = Color.WHITE) -> void:
|
|
var frame_size = Vector2((texture.get_width() / frames), float(texture.get_height()))
|
|
var current_frame = fmod(floorf(time * fps), frames)
|
|
canvas_item.draw_texture_rect_region(
|
|
texture,
|
|
Rect2(-frame_size * 0.5, frame_size),
|
|
Rect2(Vector2(current_frame * frame_size.x, 0.0), frame_size),
|
|
modulate
|
|
)
|