Thursday, 24 April 2014

Transition Manager Class

I've spent some time writing a library that transitions between two scenes (displayGroups in practice) as part of my experiments in MVP - I don't think Composer will do without a lot of faffing about.

It is a little sneaky this as I have used the transition definitions that were in the legacy storyboard system, though the rest of the code is all mine.

Its usage is like this.

local transitions = require("transitions")

local recipient = {}

function recipient:transitionCompleted()
scene1.isVisible = false
print("Done !")


It doesn't actually return a library instance, it returns a singleton object which is an instance of TransmissionManager - it only needs one. This is then instructed to do a 2 second zoomInOut transition between scene1 and scene2 (I have cut this code out that creates it, but it is in the demo).

scene1 and scene2 are two displayGroups, 1000 is the time allowed for each 'phase' of the transition (so if you fade it will take 2000ms in total).  The recipient is an object which receives notification (as you can see in the example) when it is completed. All it does is print("Done !"). You can pass only one scene if you like, either "from" or "to".

It is slightly different ; it returns the scenes unchanged and visible, so if you run the example it will work and if you took the scene1.isVisible line out it would display both of the scenes.

This is a decision I made, basically :) It returns a stable state back.

It won't really be used on its own, it will be used eventually, probably in modified form, as part of my MVP stack, rather than the Components wrapper, which is probably a dead end, too reliant on Corona SDKs slightly strange methodology. There aren't any overlays, yet.

No comments:

Post a Comment