Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Best technique to create infinite sidescroller  (Read 201 times)

0 Members and 1 Guest are viewing this topic.

paupav

  • Full Member
  • ***
  • Posts: 156
    • View Profile
    • Email
Best technique to create infinite sidescroller
« on: November 16, 2023, 10:43:29 pm »
Hi all,
I couldn't find any thread regarding best techniques to create infinite sidescroller.
I thought there would be something like sf::View::set_loop(bool); function that would make it so that if you sf::View::move() outside of the view it would overflow to show start. But there isn't such a feature  :(

For example think of a game like flappy bird, one would want to simply create 2xWidth render size view and infinitely scroll, add pipes as it goes along and view gets recycled
But just keeping bird steady and moving pipes is ok too I guess.
« Last Edit: November 16, 2023, 11:05:52 pm by paupav »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Best technique to create infinite sidescroller
« Reply #1 on: November 16, 2023, 11:55:29 pm »
Nothing is ever "truly infinite". You always have to either trick the infinity or set an overall limit.

Say if you just keep moving a view, you'll eventually end up with float imprecision at one point.
And if you just keep the character static and move the "background", then you're not really "scrolling", but create an illusion that you are.

If you want an infinite sidescroller, you're probably best off keeping the player centered and dynamically loading and drawing the map as you go.

If you have the same repeating area, you can just render the world the player is in right now and render the same world ahead of behind, but offset so you can just move the world and it looks to the player as infinitely repeating.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything