Continious jump on touch event

Hi!

Trying to make my character keep on jumping as long as the button is pressed… Been searching for this but havn’t figured out how to make it work…

The canjump argument is a check to see if the character i touching the ground or not…

Any help would be highly appreciated!

All my best!

[lua]local function onTouch( event )

local touched = event.target
if ( canjump == “true” and event.phase == “began” ) then
stick:applyForce( touched.xForce, touched.yForce, stick.x, stick.y )

end

end

for i=1,#touchObjects do
touchObjects[i]:addEventListener ( “touch”, onTouch )
end[/lua] [import]uid: 187595 topic_id: 32454 reply_id: 332454[/import]

The reason why it’s not jumping is because you created a single touch listener. So your function responds to the single touch event and that’s the end of it. What you can do is create a timer on event.phase == “began” that runs a function every 100 ms or so that does the same thing

if canjump == true then  
stick:applyForce( touched.xForce, touched.yForce, stick.x, stick.y )  
end  

and then on event.phase == “ended” for your touch event you just cancel that timer. You can also try using a runtime event listener but that’s probably nastier. [import]uid: 77199 topic_id: 32454 reply_id: 129112[/import]

The reason why it’s not jumping is because you created a single touch listener. So your function responds to the single touch event and that’s the end of it. What you can do is create a timer on event.phase == “began” that runs a function every 100 ms or so that does the same thing

if canjump == true then  
stick:applyForce( touched.xForce, touched.yForce, stick.x, stick.y )  
end  

and then on event.phase == “ended” for your touch event you just cancel that timer. You can also try using a runtime event listener but that’s probably nastier. [import]uid: 77199 topic_id: 32454 reply_id: 129112[/import]