I have a text file that I am using for my map for the tiles to be allocated. This works fine, but I am running into issues figuring out how I would go about loading in a different part of the map.
For example, say I wanted the character to go into a cave or building, what would be a good way to go about loading this new area?
Right now I have my handler class setting the world in my game state class, and I have tried messing around in the game state class to try and accomplish what I want but have not had much success. In that game state class I have a tick and render method, and in the constructor I have it being set.
The methods that I have tried have resulted in a new map to be loaded in, but the other map is still loaded in under this, and I know this because the character has collisions set up. This also goes along with this issue, but what would be a good way to trigger this loading of the new section of the map?
Below is the code in my GameState class. (changeWorld
is based off of the X coordinate when in game, and once you reach a certain point it switches maps; this was just done for testing because it is not an accurate way of doing it).
// Constructor...
World1 = new Worlds(handler,"resources/Worlds/world1.txt");
SpawnWorld = new Worlds(handler,"resources/Worlds/world2");
if(Worlds.changeWorld() == false)
handler.setWorld(World1);
}
else if(Worlds.changeWorld() == true) {
World1=SpawnWorld;
handler.setWorld(World1);
entityManager.setPlayer(new Player (handler, 0,0));
}
}//end contructor
public void tick() {
if(Worlds.changeWorld() == false) {
World1.tick();
}
else if(Worlds.changeWorld() == true){
World1=SpawnWorld;
handler.setWorld(World1);
SpawnWorld.tick();
}
}//end tick
public void render(Graphics g) {
if(Worlds.changeWorld() == false) {
World1.render(g);
}//end if
else if(Worlds.changeWorld() == true) {
World1=SpawnWorld;
handler.setWorld(World1);
World1.render(g);
}
}//end graphics
if(Worlds.changeWorld()==true)
you could simply writeif(Worlds.changeWorld())
\$\endgroup\$