You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The pattern I've been using for this is to reload the map in the Game class and add:
classMyGame {
...
Future<void> reloadLevel() async {
awaitloadWorldAndMap(
tiledMapPath:'map.tmx',
tiledObjectHandlers: tiledObjectHandlers,
);
// Don't let the camera move outside the bounds of the map, inset// by half the viewport size to the edge of the camera if flush with the// edge of the map.final inset = camera.viewport.virtualSize;
camera.setBounds(
Rectangle.fromLTWH(
inset.x /2,
inset.y /2,
leapMap.width - inset.x,
leapMap.height - inset.y,
),
);
}
@overridevoidonMapUnload(LeapMap map) {
player?.removeFromParent();
}
@overridevoidonMapLoaded(LeapMap map) {
if (player !=null) {
world.add(player!);
player!.resetPosition();
}
}
}
And make sure to call game.reloadLevel() from the Player when the player dies
I would like to have an easy way to reset the map.
My use case is this: when the player dies, he respawns at the starting position and the map SHOULD be reset.
Right now, there is no easy way to do this. So having a .reset() like function inside the LeapMap would help a lot.
The text was updated successfully, but these errors were encountered: