0 votes

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

in Engine by (25 points)

1 Answer

0 votes

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]
by (35 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.