Sequence.lua - Transition Execution order

Posted by calledpaul, Posted on October 17, 2011

1 vote

Hello everybody!

I am a bit new to Corona but i am working on a game template. Below you can find the class i wrote to handle sequential animations (function calls). It's really easy but i think it will be helpful for somebody here.
My idea is to integrate it with TransitionManager somehow, but still havent stated with that, if somebody has any ideas about it i will be glad to here them.
PS: I think methods like stopTransitions and pauseTransitions should be implemented here.

Any feedback or improvements will be appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-----------------------------------------------------------
-- Copyright (C) 2011 Paul Ryabchuk. All Rights Reserved.
-----------------------------------------------------------
-- sequence
--
--local s = require('sequence'):create({
--      {'a', {onComplete = function() print('aFunc') end }},
--      {'b', {onComplete = function() print('bFunc') end }},
--      {'c', {onComplete = function() print('cFunc') end }},
--      {'d', {onComplete = function() print('dFunc') end }}
--})
--s:start()
-----------------------------------------------------------
 
local M = {}
 
function M:create (items)
    
    local s = {}
    s.funcs = {}
 
        local len = #items
        
        for i=len, 1, -1 do
                local item = items[i]
                if (i < len) then
                        if(item[2]['onComplete'] == nil) then
                                item[2]['onComplete'] = s.funcs[len-i]
                        else
                                local oFunc = item[2]['onComplete'];
                                item[2]['onComplete'] = function()
                                        oFunc()
                                        s.funcs[len-i]()
                                end
                        end
                end
                table.insert(s.funcs, function ()
                        print(item[1])
                        if (type(item[2].onComplete)=='function') then
                                timer.performWithDelay(1000, item[2]['onComplete'])
                                --transition.to( item[1], item[2] )
                        end
                end)
        end
 
    function s:start ()
                self.funcs[#self.funcs]()
    end
 
    return s
end
 
return M