0 votes

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?

in Engine by (18 points)
edited by

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

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

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

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.

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

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

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.

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
etc...

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

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...

I looked around other places and found this
https://codepen.io/vincentorback/pen/zxRyzj
I'm not good at JS but hopefully i could learn something from it.

1 Answer

+1 vote
Best answer

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 Scroller.gd
I hope i haven't forgotten something.

by (1,412 points)
selected by

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.

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 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.