nightm4re here is my whole main class, I explain what I'm trying to do after the code below:
public class Client {
public static void main(String[] args) {
Game.info().setName("TestGame");
Game.info().setSubTitle("");
Game.info().setVersion("1.0.0");
Game.init(args);
Game.graphics().setBaseRenderScale(1.00f);
Game.world().addListener(new EnvironmentListener() {
@Override
public void loaded(Environment environment) {
try {
MapWarpsResponse response = RequestUtils.sendRequest(new MapWarpsRequest(GameResources.getMapId()), MapWarpsResponse.class, new URI("/maps/warps"), "POST");
for (MapWarp mapWarp : response.getMapWarps()) {
Trigger trigger = new Trigger(Trigger.TriggerActivation.COLLISION, pad(mapWarp.getId(), 6));
trigger.addActivatedListener(triggerEvent -> {
try {
// Ask where to Warp
MapWarpResponse warpResponse = RequestUtils.sendRequest(new MapWarpRequest(GameResources.getMapId(), mapWarp.getId()), MapWarpResponse.class, new URI("/maps/warp"), "POST");
// Load Warp Map
Game.world().loadEnvironment(Resources.maps().get("maps/" + pad(warpResponse.getMapId(), 6) + ".tmx"));
// Warp player to new map
Player.instance().setTileLocation(warpResponse.getCoord().getX(), warpResponse.getCoord().getY());
} catch (URISyntaxException e) {
e.printStackTrace();
}
});
trigger.addActivator(Player.instance());
trigger.setLocation(mapWarp.getWarpRect().getX() * TILE_DIM, mapWarp.getWarpRect().getY() * TILE_DIM);
trigger.setWidth(mapWarp.getWarpRect().getWidth() * TILE_DIM);
trigger.setHeight(mapWarp.getWarpRect().getHeight() * TILE_DIM);
Game.world().environment().add(trigger);
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
});
// Get Character Spawn
try {
CharacterLoginResponse loginResponse = RequestUtils.sendRequest(new CharacterLoginRequest("HanHa"), CharacterLoginResponse.class, new URI("/characters/login"), "POST");
GameResources.init();
Game.screens().add(new GameScreen());
PlayerLogic.init(loginResponse.getCoordinate());
Game.world().loadEnvironment(Resources.maps().get("maps/" + pad(loginResponse.getMapId(), 6) + ".tmx"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
Game.start();
}
}
On client load, I ask a game server where to spawn (at the bottom of the class). Before that, I create an EnvironmentListener
so when any map loads it asks the server for "warps" (Triggers
) and places them on the map. Each Trigger will have a TriggerActivatedListener
to do a follow-up request to the server to get info on where the warp takes you (mapId, coordinate)
With the above code, the initial map loads and all the triggers are visible on the map in debug mode. My problem is that the triggers are not running the triggerEvent
code in the TriggerActivatedListener
made in the EnvironmentListener
.
When I put a breakpoint in the triggerEvent
lambda, I never hit it when walking over and standing in the Trigger
.
Hopefully that paints a better picture of what I'm trying to accomplish.
Thanks!