Author Topic: Smooth scroll  (Read 629 times)

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4177
    • View Profile
    • Portfolio
Smooth scroll
« on: 2019-Mar-03 »
A quick question before I open a proper thread.
I´m working on a sidescroller shooter with paralax like Shadow of the Beast.

I´m having a float add to the scroll with percentages but I sense a bit of jagging, probably when a layer does not move in rhythm with the rest.
would it be better if I break a loop in cycles and feed a pixel to each layer per cycle when appropriate? Or would that be the same?

I kind of sense that all adds to the layers must not be broken, like 1, .5, .25, .1 or at least decimals, but never something like 66.66.
It all has to be able to sum to 1 so it keeps a rhythm, Am I tripping here? What do you guys think?
<a href="http://www.youtube.com/watch?v=iaG9Xl3DF-o" target="_blank">http://www.youtube.com/watch?v=iaG9Xl3DF-o</a>

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4143
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Smooth scroll
« Reply #1 on: 2019-Mar-03 »
I wouldn't recommend using floats - they are notoriously unreliable for something that needs to be smooth. Better to use INTs and scroll at a fixed rate/value - scrolling each layer at the speed required; it all should look much smoother without any obvious lag on any layer.

I did a SOTB demo for the Wiz that ran at 60FPS with GLBasic -

https://www.youtube.com/watch?v=58O59UIP73I

I came. I saw. I played.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2602
    • View Profile
Re: Smooth scroll
« Reply #2 on: 2019-Mar-04 »
Ian is correct, floats could be the problem when you move a layer and its x-coord lands with float result(x.0-999), as GLB may round up or down to an integer for rendering. Causing your wobble.

I believe opengl renders 2d texels with sub-pixel accuracy. So it's just a pity that the GLB 2D commands are limited to integers as in this situation using floats would have made for smoother scrolling.

A slightly bonkers way to do this is a actually render the scroll layers in 3D with X_SPRITE, the camera would be using an orthogonal view (X_MAKE3D with a negative FOV). It would take some careful planning but it may get the best results. I haven't tried it though!  :S

Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 251
    • View Profile
Re: Smooth scroll
« Reply #3 on: 2019-Mar-05 »
Unfortunately, this does not solve the problem of tremor with floating values.
In fact, the only way in opengl is to create a pseudo-3D.
Here is an example that is easily adaptable (and maybe, can be transformed into a real library).
Sorry if I didn't comment more, I did it tonight and I'm a little tired (also sorry if the code is not very clean).

Use "+" or "-" to speed up or slow down scrolling.

I take this comment to salute the memory of Steve Bak who left us last month... in almost total indifference :rant:
He was the king of scrolling on Atari, vertically (Goldrunner), horizontally (Return to Genesis) and horizontally with parallax (StarRay).

R.I.P Master... :booze:  ...   :'(


http://atariage.com/forums/topic/288000-rip-steve-bak/

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3604
    • View Profile
    • Space Fractal
Re: Smooth scroll
« Reply #4 on: 2019-Mar-05 »
im remember im did used floats in a least both Karma Miwa and Genius Greedy Mouse and the camera even can zoom in and out in the last game. Howover im did allways make sure the tiles was in a Interger size as well the camera positon, so yes im did fighted with a similar issues due the floats imprecision. you can eventuelly round it and Interger it. Its was something like that im did in my games to avoid various artifact in that fact im newer used virtual screen.
« Last Edit: 2019-Mar-05 by spacefractal »
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4177
    • View Profile
    • Portfolio
Re: Smooth scroll
« Reply #5 on: 2019-Mar-05 »
Thanks for the data guys, very appreciated.
I will change the code to integers and check the results. :good:

Really sad news about Bak...

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 251
    • View Profile
Re: Smooth scroll
« Reply #6 on: 2019-Mar-06 »
Quote
I will change the code to integers and check the results. :good:

In summary, I broke my head to give you an example that works with floats for nothing  :D
Too bad, I'm sure it could have been the beginning of a beautiful library specifically dedicated to this type of games with for example sprites by layers, sprites moving between each layer, ... 
A kind of 2.5D graphic engine ;)

Quote
Really sad news about Bak...

Thank you for him  :booze:

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4177
    • View Profile
    • Portfolio
Re: Smooth scroll
« Reply #7 on: 2019-Mar-06 »
oh my! I didn´t see your code! How absurd.
For some unknown reason I went right through it.  :S

Will check it out right now!

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 285
    • View Profile
    • my personal website
Re: Smooth scroll
« Reply #8 on: 2019-Mar-29 »
hm.. I think that it depends on game, for what resolution it's designed, how other movement is done, what special effects/filters are used on final buffer, one workaround is to keep floats as 'real' layer position/translation, and have another integer based value for drawing, and as spacefractal mentioned keep scaling/zoom to integers. Generally usage of integer per-pixel translation for layers is ok, if it helps avoid some problems.
Check my source code editor for GLBasic - link

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 251
    • View Profile
Re: Smooth scroll
« Reply #9 on: 2019-Apr-06 »
No Dreamerman, even if you use a floating calculus and after an integer for the drawing, you will still have a tremor problem, especially in this type of scrolling.

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4177
    • View Profile
    • Portfolio
Re: Smooth scroll
« Reply #10 on: 2019-Apr-06 »
Like Snoopy said.

Tried his code and I found it works better than mine on that front but still stutters a little bit.
Later I found out it was something on my new computer´s gfx config that was causing the harder stutters.
Also, I´d like to keep the resolution on par with the gfx, no higher res that can do "subpixel" movement.

I´m still working a middle ground to all these but the gfx board config was really what was dragging things down.
It now stutters very very seldomly. :)

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 251
    • View Profile
Re: Smooth scroll
« Reply #11 on: 2019-Apr-07 »
I made a smoother version that also retains the resolution.
I added a fish for fun too... a future game "Flappy Fish"??  :D

Normally, there should be no problem except in case of slowing down the computer.

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4177
    • View Profile
    • Portfolio
Re: Smooth scroll
« Reply #12 on: 2019-Apr-09 »
I will give it a shot! Last code you did is quite nice, maybe this could be on the snippets too.

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 251
    • View Profile
Re: Smooth scroll
« Reply #13 on: 2019-Apr-14 »
Yes, it would be a good idea, but before I have to improve it and make it a real library so that it is easy to use (especially with x_sprite).