After a lengthy refactoring of my collision manager, I've implemented moving platforms in the Side Scrolling Platform. This screenshot requires less explanation as I've removed the debug text and rendered the actor's names.
- Platform A is moving horizontally from {256,560} to {512,560} at a speed of 32.
- Platform B is moving horizontally from {128,460} to {512,460} at a speed of 64.
- Platform C is moving vertically from {128,160} to {128,560} at a speed of 64.
I had to rewrite my collision manager because my response code hard-coded directly in the test function (but I still had response callbacks...yea, I don't really know what I was thinking.) After refactoring, I now have an "ActorTerrainCollision" response callback, in which I respond to collision between an actor and a tile, and an "ActorActorCollision" response callback, in which I respond to collisions between two actors.
To implement moving platforms, I've added a property to my PlatformerActor class named 'Link.' Whenever an actor (Actor1) lands on the top of another actor (Actor2), I set Actor1's Link to Actor2. Then, when updating, I apply the Velocity associated with Actor1.Link to Actor1's position. Thus, as Actor1.Link moves, so does Actor1.
[As I was typing this, I realized a small bug. The only time I clear an Actor's Link is if they jump, which on CharacterActor's can do (CharacterActor is derived from PlatformerActor. PlatformerActor is used for anything from crates to platforms to people, whereas CharacterActor is used for only people.) So, after walking off of a platform, I continue move along with my link.]
I was thinking a while ago about having a system where every single object was always linked to some kind of parent and had its own transform updated by its parent every frame, then for objects not on moving platforms, I could just set their parent to the world, which just had a null transform.
I think that may be a solution that allows for stacking objects on moving platforms etc but it's just a theory, not actually implemented. One thing puzzling me is the order to update all the transforms. Maybe you would have to build some kind of tree then iterate down from the root (the world), applying the transform to each leaf.
If it's any consolation, it is pretty much accepted as impossible to get moving platforms working right in Box2D so they won't be putting an appearance into Squishy.