Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Stop Menu scroll

Author
Message
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 2nd Feb 2022 13:55
I am scrolling my menu up and down

Text and sprites together

This works real good, no problems

How do i stop them from scrolling after you get to a point?

Here is my simple scroll code

I tried something like

if ytextpos<0 then SettextPosition(level_select_text[x],xtextPos,ytextPos+5)

But this only does it for one text not all, they all scroll to 0 then stop all behind each other.

The author of this post has marked a post as an answer.

Go to answer

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 2nd Feb 2022 14:43 Edited at: 2nd Feb 2022 14:43
It only works for one because you are only asking it to do it for one - specifically the one refenced by x in the array.
If you want to perform the task on all text objects then you need to loop through the text array and perform that task on all of them.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 2nd Feb 2022 15:21
Ok I did this



and this is what happens, there all stopping at 0



Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 2nd Feb 2022 16:25
Ok, I figured this out.

I had to make a single out of array text and sprite and get there pos for y

then if there y is out of bounds make the whole array stop moving or reposition.

here is my solution.

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 2nd Feb 2022 19:32 Edited at: 2nd Feb 2022 22:53
Your first solution, which you say sets every text objects y position to zero (actually sets them to 5) does so because of this:

In that you are checking if the y position of every text object is zero and then adding 5 to it. You are doing that in a loop which updates every text object that has the ID of [t]

A better solution would be to check the y position of the first text object before the loop. Like this:
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 3rd Feb 2022 00:36
Ok I tried this and it works but then when I scroll up to 0 I can not longer scroll.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 3rd Feb 2022 04:51 Edited at: 3rd Feb 2022 04:58
related is this scrollbox example where the premise is to limit the text (or menu in your case) to specific bounds at the top and bottom.

i can't visualize how your menu is supposed to look from the screenshot but if you have multiple elements (vs 1 like my text object), set a max top and max bottom, regardless.

you could also just set a limit to the topmost object and use it as a reference for all subsequent objects.

note, you may also want to use the scissor commands as in that example if you're not already
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 3rd Feb 2022 09:00 Edited at: 3rd Feb 2022 09:09
This post has been marked by the post author as the answer.
Quote: "Ok I tried this and it works but then when I scroll up to 0 I can not longer scroll."

That is to be expected.
I wrote that code to match the specification that you asked for - to stop it scrolling when it reaches zero.
I could rewrite it to match your new request but if I keep writing code every time you want the slightest change then you are not going to learn anything, and I would be the one to have written your game.

I'm still happy to help though, so I'll talk you through why it doesn't move after getting to zero and suggest some ways to change that.

So firstly, why does it no longer move when it gets to zero?
Let's assume that the uppermost text object (level_select_text[0]) has a Y position of 4. When it gets to this line:

We ask: Has the wheel moved in any direction (this is important later) and is the text object level_select_text[0] 's Y position greater than zero?
Yes to both, so we continue and loop through all text objects updating their Y position.

Now, lets assume that the wheel has moved enough to move the text objects 5 units up. The next time through the loop text object level_select_text[0] 's Y position is -1. So when we get to this line again:

Has the mouse wheel moved? Yes
Is text object level_select_text[0] 's Y position greater than zero? No
So we skip the loop and don't update the position of any text object.

That's why it behaves the way it does. So how to fix that so that it is still able to move down?

At the moment you are checking to see if the mouse wheel has moved with no care about which direction it has moved.
A simple solution would be to ensure that the loop to move the text objects only occurs if the text object level_select_text[0] 's Y position is greater than zero and the mouse wheel has scrolled upwards.
Once you have that, you can see it's a very small step to also stop scrolling in the other direction when some maximum value is reached.

One final thing to mention:
You are checking and moving the text based on GetRawMouseWheel() So if you move the mouse wheel one click, it's value will change and remain changed, moving the text objects up every frame.
Instead you should be using GetRawMouseWheelDelta() which only returns the amount the mouse wheel has moved since the last frame. The value will be very small and you will probably need to multiply it by some value to move your text.

Login to post a reply

Server time is: 2024-04-26 04:45:49
Your offset time is: 2024-04-26 04:45:49