Greetings… !
i want to work with some swipe functionality…
actually I’ve made a button hanging by a chain, so what i want to do is that whenever i swipe the chain ,it breaks and the button fells down.
* i am using storyboard
the functions that i made are here,
function swipe(event)
if event.phase == “began” then
beginX = event.x
beginY = event.y
end
if event.phase == “ended” then
endX = event.x
endY = event.y
if ((beginX<150) and (endX>150 and endX<300)) and ((beginY>=17 and beginY<=204) and (endY>=17 and endY<=204)) then --/// this is the area in which the swipe is accepted…
–// i want here the chain to break
–// but how ?
–// I’ve tried these 2 methods below mentioned, but not working
--display.remove(quitLog)
– table.remove(quitJoints)
end
end
end
after the condition is fulfilled i want the chain to break.
the chain function is
function quitchain( )
quitLog = display.newImage(“quitButton.png”)
quitLog.width = quitLog.width*1.5
quitLog.height = quitLog.height*1.5
physics.addBody(quitLog, { density = 2.0, friction = 0, bounce = 0}) —// BUTTON
physics.setGravity(0,3)
sg:insert(quitLog)
for j = 1,12 do
link[j] = display.newImage( “link.png” ) --// TRANSFORMING THE CHAIN(12 chain pieces)
link[j].x = 150
link[j].y = 0 + (j*17) – start =17 , end =204
physics.addBody( link[j], { density=2.0, friction=0, bounce=0 } )
sg:insert(link[j])
– Create joints between links
if (j > 1) then
prevLink = link[j-1] – each link is joined with the one above it
else
prevLink = beam
– prevLink = quitLog – top link is joined to overhanging beam
end
quitJoints[#quitJoints + 1] = physics.newJoint( “pivot”, prevLink, link[j], 50 + (i*100), 0 + (j*17) )
end
quitLog.x = 50+ (i* 100)
quitLog.y = 0 + (17*15) --///////////// BUTTON JOINED TO THE BOTTOM OF THE CHAIN
link[12] = quitLog
quitJoints[#quitJoints + 1] = physics.newJoint( “pivot”, prevLink, quitLog,50 + (i*100), 0 + (17*15))
end
function scene:createScene( event )
quitchain()
end
function scene:enterScene( event )
Runtime:addEventListener(“touch”, swipe)
end
the chain is placed in table, how can i break it at the place where it is touched by the swipe ??
please help me out . Thanks