Can a array hold sprites in it

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Pratik

i am creating a scrolling book and all sprites are pages …does array can contain sprites through which i can scroll and show current one and go back and forth

:bust_in_silhouette: Reply From: NaughtyGnosiophile

An array can contain anything. So you can hold all the sprites in an array and keep an index pointing at the current sprite.

var sprites = [sprite1, sprite2, sprite3]
var current_sprite = 0

func move_next():
   current_sprite = min(current_sprite +  1, sprites.size() - 1)
   return sprites[current_sprite]

func move_prev():
   current_sprite = max(current_sprite - 1, 0)
   return sprites[current_sprite]