Hello!
a newbie here, this is my first post! I have a sprite which falls to the ground and i want it to go up while touching the screen, and then fall down again, but i only succeed to get it to jump up little. It only reacts every time i click with the mouse in the simulator and not while i am holding the mouse button down.
This is my code:
function spriteInstance2:touch(event)
if (event.phase == “began”) then
print(event.x)
spriteInstance2:setLinearVelocity(0, -100)
end
end
Runtime:addEventListener(“touch”, spriteInstance2)
i know that i only listens after the began phase so of course it won’t continue to push my sprite up but really need help to do it because i just can’t get my head around it?
Sorry for my bad english=)
Kind regards Isak
(Edit)
Solved it before anyone answered but i thought i should tell how i did and i just used a timer with touch ended like this:
function spriteInstance2:touch(event)
if(event.phase == “began”) then
tmr = timer.performWithDelay(100, vel, -1)
elseif(event.phase == “ended”) then
timer.cancel(tmr)
end
end
function vel(event)
spriteInstance2:setLinearVelocity(0, -event.count * 50)
end
Runtime:addEventListener(“touch”, spriteInstance2)
This way it keeps pushing the object upwards as long as button is pressed and stops then i release, it also goes faster and faster the longer the button is pressed.
maybe someone else can find this useful=)
Kind regards Inkoqnito [import]uid: 90942 topic_id: 15772 reply_id: 315772[/import]
