Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smooth scrolling #1

Open
cveld opened this issue Mar 30, 2016 · 1 comment
Open

Smooth scrolling #1

cveld opened this issue Mar 30, 2016 · 1 comment

Comments

@cveld
Copy link

cveld commented Mar 30, 2016

Now JavaScript engines have boosted in performance, I was trying to get your prettytiles-gamejs implementation running with 30 fps and smooth scrolling. Unfortunately, it is not trivial. Do you have time to fix this?

I changed the fps to 30:

gamejs.time.fpsCallback(tick, this, 30);

I modified the increments a bit:

    case gamejs.event.K_a:
       ew_mv_size -= 8;
       break;
    case gamejs.event.K_d:
       ew_mv_size += 8;
       break;
    case gamejs.event.K_w:
       ns_mv_size += 4;
       break;
    case gamejs.event.K_s:
       ns_mv_size -= 4;
       break;

I tried to cast x_rnd and y_rnd to integers, but that is not enough. The animations still look jagged:

      var x_part = xoff % 32;
      var x_rnd  = Math.floor(xoff/32);

      var y_part = yoff % 16;
      var y_rnd  = Math.floor(yoff/16);
@oberhamsi
Copy link
Owner

thanks for reminding me of this old project :) I updated the code to run with the newest gamejs.

prettytiles now runs much better but this algorithm doesn't provide smooth scrolling. i can imagine one way to do it, would be to render the tiles into an offscreen canvas and copy the right subsection onto screen.

changes: 2b047a6...25a9265

if you want the new code to run at full speed remove this return condition, which limits it to one update every 50ms:

https://github.com/oberhamsi/prettytiles-gamejs/blob/master/src/main.js#L85

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants