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

Author Topic: Loading maps as the player walks  (Read 1823 times)

0 Members and 3 Guests are viewing this topic.

Mhez

  • Newbie
  • *
  • Posts: 3
    • View Profile
Loading maps as the player walks
« on: July 29, 2013, 06:15:12 pm »
Hi,

I want to make a top-down game (similar to zelda) with many maps, but make it look that it is just one big map. My idea was to make every map the size of the screen and load all the adjacent maps as the player walks.

The thing is that I don't know if changing the view is the best way of doing this, as making calculations with negative numbers gets a little tricky, and I feel that I would not be using it the right way (as sfml coordinates won't make sense if I load at (0,0) the map the player was the last time he played (maps would be on different coordinates every time the player starts playing).

I would like to know if someone has attempted to do something similar, if someone has a different aproach than the one I explained here, or even if I should keep going with my idea for the right reasons.

Thanks in advance and please forgive me for my bad english!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10998
    • View Profile
    • development blog
    • Email
Re: Loading maps as the player walks
« Reply #1 on: July 29, 2013, 06:33:38 pm »
You can do that, you'll just have to understand how views work.
The hard part is obviously to load the map as you're walking. Loading the map from the same thread will block that thread for the time of loading, thus it looks like your game would be frozen. To prevent that, you'll have to load it in another thread.

It's all doable, but before you try to implement that on-demand loading, why don't you create a working system that pre-loads the map. It's harder the get done, than it looks like at first. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Mhez

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Loading maps as the player walks
« Reply #2 on: July 29, 2013, 06:42:29 pm »
Hmm.. So you think I should first get into threads and try to load the maps? Well, I'm new to c++, hopefully threads will be similar to the ones in C# xd

I'll try, thanks for the answer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Loading maps as the player walks
« Reply #3 on: July 29, 2013, 06:43:47 pm »
The thing is that I don't know if changing the view is the best way of doing this
Yes, and it's the simplest way. You store a global coordinate of your player, and depending on that you know which part of the map to display.

For example (analogue for Y coordinate):
screen/map part width:  w = 800
player X coordinate:    x = 1700
left border:            l = x - w/2 = 1300
right border:           r = x + w/2 = 2100

left part:      floor(l / w) = 1    -> second part
right part:     floor(r / w) = 2    -> third part

0        800      1600      2400
+----0----+----1----+----2----+
                 l----x----r

No, don't get into threads. That's why he wrote you should pre-load the map, which can be done without threads.

By the way, if you're new to C++, I recommend reading a good book such as C++ Primer. Even if C# looks like a similar language, it totally isn't. You have to re-learn a lot of things.
« Last Edit: July 29, 2013, 06:49:05 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Mhez

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Loading maps as the player walks
« Reply #4 on: July 29, 2013, 06:50:25 pm »
Preloading the maps means loading all maps before playing? Making 1000 maps wouldn't take many time to load? I pretend to make maps with multiple layers and variable tile sizes,

thanks for the quick answers

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10998
    • View Profile
    • development blog
    • Email
Re: Loading maps as the player walks
« Reply #5 on: July 29, 2013, 06:58:31 pm »
Preloading the maps means loading all maps before playing?
Yes! :)

Making 1000 maps wouldn't take many time to load? I pretend to make maps with multiple layers and variable tile sizes,
It will take more time etc, but it's easier to start simple and expand once you actually get something done.
I can assure you, that the dynamic map loading will not be the first major problem you'll run into while getting the game to a usable state! :D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything