Monday 28 April 2014

Working on my own version of Composer.

I'm working on my own version of Composer.

I have separated the Transitions into a separate library - so the transitions bit now just does a transition from one scene to another (or a scene from/to no scene), and a Scene Manager with some scene classes that uses the Transition library.

It sort of works at present - it needs some extra testing, but it allows the declaration of classes for scenes, e.g.

SceneClass = sm.Scene:new()

function SceneClass:create()
local vg = self:getViewGroup()
self.text = display.newText("Scene "..self.id,160,240,native.systemFont,32)
vg:insert(self.text)
self.text:addEventListener( "tap", self )
print("Scene "..self.id.." create")
end

function SceneClass:tap(e)
self:gotoScene(self.tgt)
return true
end

function SceneClass:setup(id,tgt) self.id = id self.tgt = tgt return self end

function SceneClass:getTransitionType() return "slideright" end

s1inst = SceneClass:new():setup("One","secondscene")
s2inst = SceneClass:new():setup("Second one","firstscene")

smgr:append("firstscene",s1inst):append("secondscene",s2inst)

smgr:gotoScene("firstScene")

So it declares a new scene class, which just plonks some text on the scene and attaches a listener to it. which goes to another scene (the 'setup' method is just to name the scene and where it goes after easily, it's a bodge for testing).

The getTransitionType() method defines the transition - it then creates two separate instances of the class (s1inst and s2inst), adds them to the known classes, and goes to the first scene (smgr is an instance of "SceneManager", sm is an instance of the SceneManager library).

It's on github https://github.com/autismuk/Scene-Manager but it is definitely a work in progress.

No comments:

Post a Comment