position of sprite

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

Hello! I am a beginner in game engines, godot is the first one i used. I have used this game engine for like 3days now, and i am trying to make a customization menu. The problem is the hair sprites have different dimensions,because the player can choose from either very long hair or very short.
I have a variable called “hairnum” for the model of hair. For example, for hairnum=1 i want the y position to be 15, and for hairnum=2 i want the y position to be 20. How do i do that? I tried searching on youtube or chrome but i didn’t really understand. I’m saying again that i do not know a lot, i am only at the beginning, so i appreciate any help.

:bust_in_silhouette: Reply From: Adam_S

You could make an array with the y positions in it

var hair_positions = [15, 20, ...]

then if hairnum changes get the position

sprite.position.y = hair_positions[hairnum]

Note that hairnum has to be 0 to get the first position in the array, 1 for the second and so on. Or subtract 1 like

sprite.position.y = hair_positions[hairnum-1]