Teleporting Across Maps with Entity References #113
Replies: 2 comments
-
Much of the difficulty seems to stem from an inability to search for UUIDs across levels. (It is possible this functionality does exist and I've simply not encountered it.) I wonder if the structure of LDTK worlds is such that a search for an entity can be done in a reasonable time? Would it be a mess? Are there other use cases for searching for a UUID across levels? |
Beta Was this translation helpful? Give feedback.
-
I had the same issue. Your message helped me allot! Thank you. This is my summary:
In the source of this library, I saw a few things that give me the impression it should be possible to spawn more than just the entities within the current level. Have a look at My Door implementation: |
Beta Was this translation helpful? Give feedback.
-
First off, kudos to Trouv for making this library. It's proving to be very friendly and enjoyable to use. This is a curiosity which I'm "immortalizing" because I suspect others will encounter a similar architectural question when it comes to referring to things across maps. All that said, let's begin:
LDTK has the ability to link entities across levels. I'm using it my game to connect doors to exits across two different levels. In the platformer example, levels are changed when a player exits one side of the map. The connection between locations is implicit, but this isn't always the case, especially if one is "teleporting" via a door or portal.
When I create the door object inside of the map, it gets an Area2D assigned and a DoorDestination component. The DoorDestination is just a simple FieldInstanceEntityReference. Personally, I would rather just get the XY of the target location in the destination, but the new level isn't loaded, so it's not defined. I can think of a few ways to solve this but am not sure what's best.
Possible solutions:
Make a Transition resource which gets drawn on top and add a "teleport on complete" handle, but this feels like mixing a bunch of functionality in one system. The resource would have a "fade" amount, a fade direction, a destination level, and a destination position. The system will perform a fade and, when completely faded, change the level, then check for the loaded entity and set the player's transform correctly.
Hard-code the XY in the Entity attributes for doors. I don't like this one, but it's important to list it. LDTK does allow people to attach a Point attribute to entities, but there are issues related to linking across levels and problems with usability if the level gets moved around. (You need to update old references. Bleh.)
Attach a Teleport component to the player object which triggers a teleport when the desired object is loaded. This is not dissimilar to the first solution, but the component goes on a player and just checks for <Added> and then teleports. It's more specific than the general fade and doesn't do as much mixing of intents.
Make an Event and have the LDTK map loader actually teleport the player when an entity with the given UUID is spawned. This would be like a
process_spawned_level_entity
system but would use Events instead ofAdded<EntityInstance>
. It makes me a little nervous because dropped events could leave the player in the void.Thoughts are appreciated. I'll link the code when I've decided.
Beta Was this translation helpful? Give feedback.
All reactions