An idea behind Loop Scrolling Menu?

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

Hi everyone,
I’m developing my project where I have a shop merchant selling stuff and I want to have a menu scrolling through the items until it reaches the final item then loop back to the first one.
Each item contains sprite and text.
Does anyone know the principle or optimal way to do this?

Should it go up to the start, or just repeat at the bottom, so you have endless scrolling?

whiteshampoo | 2020-07-22 05:26

It should keep scrolling to give a visual of infinite loop.

fairyhell | 2020-07-22 06:28

Are you using a control-node to show the items, or are they sprites?

whiteshampoo | 2020-07-22 09:16

I’m using sprite but I could change it if necessary.
Each Item shown is actually an instance of a scene where I will change sprite and text.

fairyhell | 2020-07-22 09:54

I’ll let you know if i found a good solution. (I’m at work at the moment…)

whiteshampoo | 2020-07-22 10:29

what should happen, if there are not enough items to fill the list?

whiteshampoo | 2020-07-22 11:45

Like if there are none?
If the item are sold, then it will be gray out or replace with sold or something as a place holder, or maybe just reduce the visibility of the list down to fits what item are shown. (Keep looping 1 or 2 items over)

But as long as the loop is achieved, I’d like to try to work everything else out on my own.

And I really appreciate your reply btw.

fairyhell | 2020-07-22 12:41

the key to make this possible is “Modulo” (%)

it’s like divison, but will give you the remainder.
0 % 3 == 0
1 % 3 == 1
2 % 3 == 2
3 % 3 == 0
4 % 3 == 1

maybe you can fiddle it out by yourself :stuck_out_tongue:
i’ll try when i’m home. (i have open end work today…)

whiteshampoo | 2020-07-22 13:27

ok, this gets much more complicated than i thought, especially because my arch-enemy the viewport-node is not cooperating…
i hope i can give you results tomorrow…

whiteshampoo | 2020-07-22 19:07

I looked around other places and found this
I’m not good at JS but hopefully i could learn something from it.

fairyhell | 2020-07-24 05:28

:bust_in_silhouette: Reply From: whiteshampoo

So, after rewriting the whole thing, because windows decided to corrupt some files, i have a more or less good solution:

Download Project

I wanted to make the items selectable, but i think i need to learn more about that Vieewport-Node… somehow my signals don’t want to work inside another Viewport.
Maybe it has something to do with this.

Code is not really complex, so i haven’t commented it.
Should be self explanatory.
If you have questions, feel free to ask.
(You can change the amount of items in the list in_ready in
I hope i haven’t forgotten something.

It looks nice to me. Thank you for the help!
It wouldn’t be hard to make a “selector” if we can get the position of the items, i think.
Like a slot machine.

fairyhell | 2020-07-25 09:36