Anyone has done a “flick” detection before? Such that a flick can throw a display object screen out of screen? Any advice appreciated.
I need this as well…
Perhaps in the touch function you could put:
[lua]
if event.phase == “began” then
eventStartX = event.xStart
eventStartY = event.yStart
elseif event.phase == “ended” then
object:applyForce( (eventStartX - event.x) * 5, (eventStartY - event.y ) * 5 )
end
[/lua]
I’m not sure if this would work, but I’ve made slingshot systems do something similar.
hmm no errors but it doesn’t work. Heres my code
flick = function ( event )
if event.phase == “began” then
eventStartX = event.xStart
eventStartY = event.yStart
elseif event.phase == “ended” then
ball:applyForce( (eventStartX - event.x) * 5, (eventStartY - event.y ) * 5 )
end
end
ball:addEventListener( “touch”, flick)
OK, so I made a little thing and had it like this:
[lua]
function flick(event)
if event.phase == “began” then
elseif event.phase == “moved” then
--dragging the ball
ball.x = event.x
ball.y = event.y
elseif event.phase == “ended” then
--applying force on the ball
ball:applyForce( (ball.x) * 0.5, (ball.y) * 0.5, ball.x, ball.y )
end
end
ball:addEventListener( “touch”, flick )
[/lua]
I removed the eventStartX and eventStartY variables because they were unnecessary and added dragging the ball in the event.phase == “moved” so that the ball moves when you touch it as well. I also changed the positions of the applyForce equations because I was using the equation for slingshots.
EDIT: It was a little bit jumpy and weird. Especially if you drag the object slowly and let go as it acts as more of a slingshot (which is what I have experience with) or change directions (again, because it acts as more of a slingshot. So I changed it a little bit.
so I can drag the object but it does not slide… I want to be able to throw it… off the screen.
Did you add the ‘event.phase == “moved”’ portion? Because it’s sliding for me when I do that.
really? I just deleted my code and added what you just posted… hmm
wow I’m retarded. My object was static… I changed it to dynamic and it worked… thanks!
Its not working the way I would like it to work. I am having the balls fall from the top of the screen anD they are dynamic body types and I want to be able to swipe them off the screen.
I need this as well…
Perhaps in the touch function you could put:
[lua]
if event.phase == “began” then
eventStartX = event.xStart
eventStartY = event.yStart
elseif event.phase == “ended” then
object:applyForce( (eventStartX - event.x) * 5, (eventStartY - event.y ) * 5 )
end
[/lua]
I’m not sure if this would work, but I’ve made slingshot systems do something similar.
hmm no errors but it doesn’t work. Heres my code
flick = function ( event )
if event.phase == “began” then
eventStartX = event.xStart
eventStartY = event.yStart
elseif event.phase == “ended” then
ball:applyForce( (eventStartX - event.x) * 5, (eventStartY - event.y ) * 5 )
end
end
ball:addEventListener( “touch”, flick)
OK, so I made a little thing and had it like this:
[lua]
function flick(event)
if event.phase == “began” then
elseif event.phase == “moved” then
--dragging the ball
ball.x = event.x
ball.y = event.y
elseif event.phase == “ended” then
--applying force on the ball
ball:applyForce( (ball.x) * 0.5, (ball.y) * 0.5, ball.x, ball.y )
end
end
ball:addEventListener( “touch”, flick )
[/lua]
I removed the eventStartX and eventStartY variables because they were unnecessary and added dragging the ball in the event.phase == “moved” so that the ball moves when you touch it as well. I also changed the positions of the applyForce equations because I was using the equation for slingshots.
EDIT: It was a little bit jumpy and weird. Especially if you drag the object slowly and let go as it acts as more of a slingshot (which is what I have experience with) or change directions (again, because it acts as more of a slingshot. So I changed it a little bit.
so I can drag the object but it does not slide… I want to be able to throw it… off the screen.
Did you add the ‘event.phase == “moved”’ portion? Because it’s sliding for me when I do that.
really? I just deleted my code and added what you just posted… hmm
wow I’m retarded. My object was static… I changed it to dynamic and it worked… thanks!
Its not working the way I would like it to work. I am having the balls fall from the top of the screen anD they are dynamic body types and I want to be able to swipe them off the screen.