~johanvandegriff/johanv.xyz

c18e5d89cd74b4eb93479736882692fcada88c46 — Johan Vandegriff 2 months ago 4e53110
made scrolling smoother
1 files changed, 11 insertions(+), 6 deletions(-)

M ATinyGame/index.php
M ATinyGame/index.php => ATinyGame/index.php +11 -6
@@ 217,12 217,10 @@ function loop() {

  //timers from handle_scroll
  if (scrollS > 0) {
    if (scrollS == 9) press(buttonS);
    if (scrollS == 1) release(buttonS);
    scrollS--;
  }
  if (scrollR > 0) {
    if (scrollR == 9) press(buttonR);
    if (scrollR == 1) release(buttonR);
    scrollR--;
  }


@@ 911,13 909,20 @@ var scrollS = 0;
var scrollR = 0;
function handle_scroll(e) {
  // console.log(window.scrollY, e)
  var scrollThreshold = 0;
  if (scrollEnabled) {
    if (window.scrollY - lastScroll > 25){
      scrollS = 20; //after this many frames (64 frames = 1 sec) it will have pressed and released
    if (window.scrollY - lastScroll > scrollThreshold){
      press(buttonS);
      scrollS = 16; //release after this many frames (64 frames = 1 sec)
      release(buttonR); //release the other button
      scrollR = 0;
      lastScroll = window.scrollY;
    }
    if (window.scrollY - lastScroll < -25){
      scrollR = 20;
    if (window.scrollY - lastScroll < -scrollThreshold){
      press(buttonR);
      scrollR = 16;
      release(buttonS); //release the other button
      scrollS = 0;
      lastScroll = window.scrollY;
    }
  }