How do I fix a small mistake in scroll indicator?

0 favourites
  • 4 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • Hello everyone!

    I am working on a kind of browser simulation for mobile devices, so I have done a scroll indicator to show a size of page and scrolling progress to user. I have invent this formula:

    But there is a problem about acting with the bottom edge: scrolling indicator can`t reach bottom edge and I can`t understand why. So when scrolly is max I have a little but very ugly bug:

    C3 project: drive.google.com/file/d/1XskHi_f3cqp5Z7d4K2z4Mxtj5SCouv-I/view

    Tagged:

  • the fact that it was close was more luck than anything...

    the place where you set the slider's position - you were including BrowserSliderMainPart.Height but its height is zero because you replaced it with 9patchSlider.

    the first part of that calculation (scrolly-(1080/2))/LayoutHeight) only works out to 0 to 0.5 because scrolly goes from 540 to 1620. to get it to go from 0 to 1, either multiply that result by 2, or change it to (scrolly-(1080/2))/1080)

    but that assumes the layout height will always be 2160. If you want the scrollable area to be variable, it gets a little trickier. Either you have to change the canvas size as required, or use unbounded scrolling and manually control where scrolly starts and stops.

    the second part of the above calculation needs to factor in the height of 9patchSlider, so the over-all calculation would be something like:

    (((scrolly-(1080/2))/LayoutHeight)*2*((1080-9patchSlider.Height)-179))+179

    or

    (((scrolly-(1080/2))/1080)*((1080-9patchSlider.Height)-179))+179

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • the fact that it was close was more luck than anything...

    the place where you set the slider's position - you were including BrowserSliderMainPart.Height but its height is zero because you replaced it with 9patchSlider.

    the first part of that calculation (scrolly-(1080/2))/LayoutHeight) only works out to 0 to 0.5 because scrolly goes from 540 to 1620. to get it to go from 0 to 1, either multiply that result by 2, or change it to (scrolly-(1080/2))/1080)

    but that assumes the layout height will always be 2160. If you want the scrollable area to be variable, it gets a little trickier. Either you have to change the canvas size as required, or use unbounded scrolling and manually control where scrolly starts and stops.

    the second part of the above calculation needs to factor in the height of 9patchSlider, so the over-all calculation would be something like:

    (((scrolly-(1080/2))/LayoutHeight)*2*((1080-9patchSlider.Height)-179))+179

    or

    (((scrolly-(1080/2))/1080)*((1080-9patchSlider.Height)-179))+179

    Billions of thanks! It is so hard to detect mistakes in own code. It works real perfect when layoutHeight = 2160. But I don`t understand what to do to make this formula universal for any layout height. I have fixed mistake with height(don`t know how I didn`t notice it), but multiply by 2 works only for current layout height. I think it should be a kind of proportion to deal normally with every situation.

    Deviding in 1080 also works only for 2160 px height of layout.

    So, have you any ideas to upgrade this formula to work normaly with any layoutHeight, AllanR?

    I have also tried to replace '*2' with 'LayoutHeight/1080' to make a universal proportion, but it also works only for current size of layout.

    Updated project: drive.google.com/file/d/1XskHi_f3cqp5Z7d4K2z4Mxtj5SCouv-I/view

  • OK, great thanks for help in finding my mistakes. After few hours thinking, testing and debuging I have found the ideal, universal formula and now it works perfect in any situation. So, infinite thanks to the AllanR for finding a big mistake and now formula looks like this:

    (((scrolly-(1080/2))/(LayoutHeight-1080))*((1080-9patchSlider.Height)-179))+179

    It works really great, so if anyone more neeed this, you may copy it, but I would be glad if you mention me in final titles smth like this "Special thanks to Ictic_STpe, my dog, my friends and family". Have a nice day, developers!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)