Switching Maps

So I’ve been following a bunch of different tutorials and currently I have a player and a map both rendered to the screen. What I’m wondering is how I would be able to switch from one map to another.

I’ve had some trouble finding a definitive answer, but I believe what I would need to do is hard code triggers into the level (say for example a staircase) and put them into the tile coordinates of the staircase, door, etc. tiles and make them do the map switching. But how exactly would something like this work? Or is there a better way?

It depends entirely on how your map works. If your map is, for example, a 2D array of tiles, then just pointing your array variable to a different 2D array of tiles would do the trick.

We can’t really answer this question without more info on how your code is setup. What have you tried?

Well I’m loading a png image where there is 1 pixel per tile and depending on what hexidecimal color that pixel is, it assigns that color’s corresponding tile when it renders the map.

when its time to switch maps, just load in the new one and save/alter and of your game data which will need to be saved or changed due to map change.

I’m not quite sure I understand what you mean. Can you elaborate?

Like I said, we need you to elaborate. We’ve outlined the basics: whenever you need to switch maps, just change whatever variable holds your “current” map to point to the value of your new map.

If you want anything more specific than that, you’re going to have to provide some of your code- preferably in the form of an MCVE.

Lets suppose in your main class you have a class called World and you initiate when your game launch.

world = new World("map1.png");

When you want to load another world,just make a new instance using the same variable.

if(score >= 10){

world = new World("map2.png");

}

At least I do this way,using 2d array of tiles and loading the pixels from an image.