MeBoingus
Member
Hi all,
I've run into a problem while adding a scroll bar to my game. I'm 99% sure that it can be solved with basic mathematics, but for some unknown reason, I'm really struggling.
I have a list of comments being drawn to a surface, vertically. I have a scroll bar that is being drawn at an origin point, plus a variable that is relative to how far we've scrolled through the list.
I'm trying to add the ability to click on the scroll bar and drag in order to scroll through the list.
I use this code:
To set the height and y position (an offset from its origin point) of the scroll bar.
In other words, If I move the mouse downward by 100 pixels, I need to update the commentScrollY variable to the value it would have if the scroll bar were 100 pixels below its previous position.
Any help would be greatly appreciated!
What each variable in the code means / is set to:
I've run into a problem while adding a scroll bar to my game. I'm 99% sure that it can be solved with basic mathematics, but for some unknown reason, I'm really struggling.
I have a list of comments being drawn to a surface, vertically. I have a scroll bar that is being drawn at an origin point, plus a variable that is relative to how far we've scrolled through the list.
I'm trying to add the ability to click on the scroll bar and drag in order to scroll through the list.
I use this code:
Code:
var scrollBarH = (commentsSH / commentH) * commentsSH;
var scrollBarY = (+commentScrollY / (commentH - commentsSH)) * (commentsSH - scrollBarH - 20);
In other words, If I move the mouse downward by 100 pixels, I need to update the commentScrollY variable to the value it would have if the scroll bar were 100 pixels below its previous position.
Any help would be greatly appreciated!
What each variable in the code means / is set to:
commentsSH - the height of the surface the comments are being drawn in.
commentH - the total height of all of the comments.
scrollBarH - the height of the scroll bar.
scrollBarY - the Y position of the scroll bar.
commentScrollY - the number of pixels we've scrolled (starts at 0, ends at -commentH)
commentH - the total height of all of the comments.
scrollBarH - the height of the scroll bar.
scrollBarY - the Y position of the scroll bar.
commentScrollY - the number of pixels we've scrolled (starts at 0, ends at -commentH)