Creating a world selection screen

Hi,

I am trying to create a world selection screen, I have taken some code I found on here and used it, it is kind of ok, but seems a little buggy and I don't like the click event as it seems to fire at the wrong time, can anyone see any problems or suggest anything better? I tried the slideview from corona but I didn't want a slide per screen.

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
-- LOAD MENUS
local menus = {}
local xPosHandler = {}
local function handleTouch(e)
        local phase = e.phase
        local t = e.target
        if "began" == phase then
                t.clicked=true
                for i=1,#worlds do
                        xPosHandler[i] = e.x - menus[i].x
                end
                display.getCurrentStage():setFocus(t)
                t.isFocus = true
        elseif "moved" == phase and t.isFocus  then
                t.isFocus=true
                for i=1,#worlds do
                        menus[i].x = e.x - xPosHandler[i]
                end
        elseif "ended" == phase then
                display.getCurrentStage():setFocus(nil)
                t.isFocus = true
                                                                                                
                for i=1,#worlds do
                   if menus[i].x > 240 - 80 and  menus[i].x < 240 + 80 then
                        diff  = menus[i].x - 240
                   end
                end
                                        
                for i=1,#worlds do
                        transition.to(menus[i],{x = menus[i].x - diff,time = 500})
                end                                                             
                                        
                if t.unlocked==1 then
                        if t.x > 220 and t.x < 260 then
                                global.world_id = t.id
                                director:changeScene("levelselection")
                        end
                end
        end
end
views:1442 update:2011/10/17 8:58:49
corona forums © 2003-2011