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

Author Topic: World Looping  (Read 2245 times)

0 Members and 1 Guest are viewing this topic.

JackPS9

  • Newbie
  • *
  • Posts: 28
    • View Profile
World Looping
« on: October 28, 2015, 09:13:29 pm »
Alright, just really stuck on how to pull this off.

So I have a tiled map, and that but can't figure out how to make it that when you hit the top, the bottom part of the map loops around, and you can just keep swimming/walking without ever hitting the edge of the map.

I've though about when you get to pos X/Y just update all the tiles to their new position.  Just worried that it may have a lag spike every time the player does so.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
World Looping
« Reply #1 on: October 28, 2015, 09:44:12 pm »
You learn best by actually trying things. Take the idea/solution that first pops into your mind and test it. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

GraphicsWhale

  • Full Member
  • ***
  • Posts: 131
    • View Profile
Re: World Looping
« Reply #2 on: October 28, 2015, 10:33:24 pm »
I've though about when you get to pos X/Y just update all the tiles to their new position.

That might work.

I would probably take the approach of teleporting the player and not the terrain, but whatever works.

Just worried that it may have a lag spike every time the player does so.

How do you know for sure it'll cause a lag spike when you haven't even tried it?


Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: World Looping
« Reply #3 on: October 29, 2015, 10:06:14 am »
You're overcomplicating things a lot. :)

Don't even worry about the looping aspect.

You can simplify your problem quite a lot.

For example, you'd somehow determine that for your current x and y position you'd have to draw the tile at coordinates tile_x and tile_y[/‹].

So to determine the actual tile to draw (including loops):

real_tile_x = tile_x % width_in_tiles;
real_tile_y = tile_y % height_in_tiles;

So let's assume your map is 10 tiles wide (index 0-9) and you'd like to draw the tile at offset 11 (second repeating tile), so you'd end up with:

real_tile_x = 11 % 10;

Of course, the result of this is 1, which represents the second tile/column. Job done! :)

JackPS9

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: World Looping
« Reply #4 on: October 31, 2015, 06:52:19 pm »
alright, well I'll try out just updating every tile like I was going to do, see if it hits any issues.
But before that have to re-write a small chunk of my framework again cause the section for any UI was horrible done and wasn't readable/understandable by those I asked.
So going to work with a state machine this time around.

 

anything