Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as Lua by Azlan ( 12 years ago )
local sliceTouches = {}
slicesLayer = Sprite.new()
stage:addChild(slicesLayer)
local function onTouchesBegin(event)
if(sliceTouches[event.touch.id] == nil) then
sliceTouches[event.touch.id] = {x=nil, y=nil, xs={}, ys={}, ss={}, shape = Shape.new()}
local sliceTouch = sliceTouches[event.touch.id]
slicesLayer:addChild(sliceTouch.shape)
sliceTouch.x, sliceTouch.y = event.touch.x, event.touch.y
else
local sliceTouch = sliceTouches[event.touch.id]
sliceTouch.x, sliceTouch.y = event.touch.x, event.touch.y
end
end
local function onTouchesMove(event)
local sliceTouch = sliceTouches[event.touch.id]
sliceTouch.x, sliceTouch.y = event.touch.x, event.touch.y
end
local function onTouchesEnd(event)
local sliceTouch = sliceTouches[event.touch.id]
sliceTouch.x, sliceTouch.y = nil, nil
end
local function onTouchesCancel(event)
local sliceTouch = sliceTouches[event.touch.id]
sliceTouch.x, sliceTouch.y = nil, nil
end
function onEnterFrame()
for e =1, #sliceTouches do
local sliceTouch = sliceTouches[e]
if sliceTouch.x and sliceTouch.y then
sliceTouch.xs[#sliceTouch.xs + 1] = sliceTouch.x
sliceTouch.ys[#sliceTouch.ys + 1] = sliceTouch.y
sliceTouch.ss[#sliceTouch.ss + 1] = 10
end
while #sliceTouch.ss > 0 and sliceTouch.ss[1] <= 1 do
table.remove(sliceTouch.xs, 1)
table.remove(sliceTouch.ys, 1)
table.remove(sliceTouch.ss, 1)
end
sliceTouch.shape:clear()
for i=1,#sliceTouch.xs-1 do
sliceTouch.shape:setLineStyle(sliceTouch.ss[i], 0x8080ff)
sliceTouch.shape:beginPath()
sliceTouch.shape:moveTo(sliceTouch.xs[i], sliceTouch.ys[i])
sliceTouch.shape:lineTo(sliceTouch.xs[i+1], sliceTouch.ys[i+1])
sliceTouch.shape:endPath()
end
for i=1,#sliceTouch.ss do
sliceTouch.ss[i] = sliceTouch.ss[i] - 1
end
if #sliceTouch.ss > 0 then
local x2 = sliceTouch.xs[#sliceTouch.ss]
local y2 = sliceTouch.ys[#sliceTouch.ss]
for i=#sliceTouch.ss-1, 1, -1 do
local x1 = sliceTouch.xs[i]
local y1 = sliceTouch.ys[i]
local d = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)
if d > 10 then
split(x1, y1, x2, y2)
end
end
end
end
end
stage:addEventListener(Event.TOUCHES_BEGIN, onTouchesBegin)
stage:addEventListener(Event.TOUCHES_MOVE, onTouchesMove)
stage:addEventListener(Event.TOUCHES_END, onTouchesEnd)
stage:addEventListener(Event.TOUCHES_CANCEL, onTouchesCancel)
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
Revise this Paste