Spooky Pooky #37 - Room to Move
Published on 19 Jan 2016 by Joe
Sometimes the simplest of things take an age to get working. Like room transitions. As seen in the horribly laggy gif below:
My rooms are stored as separate Tiled maps. There is an entity type called a 'transporter' which has a collision function attached to it. When a player runs into the transporter it assumes control (via a generic target property, and a corresponding owner property in the player entity).
The transporter think function then artificially keeps the player running in the same direction so that they fully enter the entity (thus disappearing out of view).
Once contained it triggers the room change logic, which looks up the destination room in a cache, loading it if not present. Simultaneously a transition effect is played. The rooms are relatively small (a handful of screens typically), so load quickly and are cached in memory.
The player is then attached to the map transporter entity in the new room (as indicated by the destination of the original trigger transporter), and control is given over to that to walk the player fully out and into the level.
The transition effect is lacking at the moment so might tinker about with that in a bit.
It all seems a bit over-complicated but it's flexible and actually straightforward in the code, plus it's driven via the standard collision triggers and think hooks of the rest of the system.