Hi Remy Rose, here is what GPT4 told me after posting your post and comment, hopefully it solves something, but I have personally had great success in using it as an development assistant.
You've raised some excellent points, and I can understand why you're concerned about efficiency. Let's tackle your questions one by one.
Collision with Multiple Tilemaps It does seem like using FlxG.collide() would be easier if you could pass an entire FlxGroup of maps, but you're correct that FlxTilemap#overlaps() would have to be called for each individual map. If you're concerned about performance, you might want to consider some optimizations:
Spatial Partitioning: Divide your game world into sections and only check for overlaps within the section where the player currently is. Caching: If a tilemap has not changed, you could cache the result of the overlap check until the player moves to a different region or the tilemap is modified. Redundant Position Checks You mentioned that you're checking the player's position twice per update: once for collision detection and once for random encounters. One solution could be to combine these checks into a single function that both handles collisions and determines random encounters. This way, you only need to check the player's position once per update.
Here's a pseudo-code example:
function update() {
// Collision checks and random encounter checks
for (map in allTileMaps) {
if (map.overlaps(player)) {
// Handle collision logic here
}
}
// Use the latest player position for random encounters
var currentPlayerPosition = player.getPosition();
randomEncounterCheck(currentPlayerPosition);
}
Final Thoughts These are just suggestions, and the best solution may depend on the specifics of your game. However, I hope these points guide you in a direction that helps you streamline your code and enhance performance.
Best of luck with your game development!