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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
| local deviceWidth, deviceHeight, widthRatio, heightRatio
deviceWidth = display.contentWidth
deviceHeight = display.contentHeight
-- Set ratiovalues for procentual calculations
widthRatio = math.floor(deviceWidth/100)
heightRatio = math.floor(deviceHeight/100)
-- Set white background
local background = display.newRect(0,0,deviceWidth,deviceHeight)
-- SET UP MASK ----------------
local dynamicMask = display.newGroup();
local maskBg = display.newRect(display.screenOriginX,display.screenOriginY,deviceWidth,deviceHeight)
maskBg:setFillColor(255,255,255)
dynamicMask:insert(maskBg);
local maskBoxX = display.contentCenterX
local maskBoxY = display.contentCenterY + (heightRatio*10)
local maskBox = display.newRect(0,0, 200,200)
maskBox.x = 0
maskBox.y = maskBoxY
dynamicMask:insert(maskBox);
maskBox:setFillColor(0,0,0);
display.save (dynamicMask, "tmp.jpg", system.TemporaryDirectory)
maskBox:removeSelf()
local mask = graphics.newMask( "tmp.jpg", system.TemporaryDirectory )
-- /SET UP MASK ----------------
local menus = {}
local num = 7
local xPosHandler = {}
diff = 0
local function handleTouch(e)
local phase = e.phase
local t = e.target
if "began" == phase then
for i=1,num do
xPosHandler[i] = e.x - menus[i].x
end
display.getCurrentStage():setFocus(t)
t.isFocus = true
elseif "moved" == phase and t.isFocus then
for i=1,num do
menus[i].x = e.x - xPosHandler[i]
end
elseif "ended" == phase then
display.getCurrentStage():setFocus(nil)
t.isFocus = false
for i=1,num do
if menus[i].x > 240 - 80 and menus[i].x < 240 + 80 then
diff = menus[i].x - 240
end
end
for i=1,num do
transition.to(menus[i],{x = menus[i].x - diff,time = 500})
end
end
end
for i=1,num do
menus[i] = display.newRect(0,0,100,100)
menus[i]:setFillColor(0,100,100,200)
menus[i].x = maskBoxX + (i-1) * 150
menus[i].y = maskBoxY
menus[i].myName = i
menus[i]:addEventListener("touch",handleTouch)
end
thisMainRect = display.newRect(display.screenOriginX,display.screenOriginY,1280,deviceHeight)
thisMainRect:setFillColor(0,255,255);
thisMainRect:setMask(nil)
thisMainRect:setMask(mask) |