Godot Version
I use Godot 4.2.1
Question
In my game, I use code to change the sprite using a sprite sheet through an index. I would like to leave a different index for the first element of the snake, so that when changing the sprite (pressing the space bar). All elements were changed except the first one. How can I implement this?
snake code example:
extends Panel
static var index : int = 0
func _process(_delta):
variate_texture()
func variate_texture():
$Sprite2D.region_rect.position.x = index * $Sprite2D.region_rect.size.x
main code example:
func _process(_delta):
if Input.is_action_just_pressed(âselect_colorâ):
snake[0].index += 1
if snake[0].index > 2:
snake[0].index = 0
https://github.com/ScelCoding/Question/tree/main - a link to the github project with my question.