Pressed button to move a character

Hi!

I want to put a button, when you mantain pressed the character will move.

i put first:

Button1:addEventListener(“touch”, moveleft)

and

function moveleft(event)

     if event.phase == “began” then      

         player.x=player.x-1

         player.rotation=player.rotation-1

     end  

end

The problem is that i have to click a lot of clicks to move. 1 click =1 movement

I want to mantain the click , and the movements grow up. I tried putting “if event.phase == “moved” then…” its made that okay, but i have to move the finger around the screen. I want to be posible to stay the finger stoped and made the sames movements like  puting “moved”.

Thanks! If you didnt undertand something sorry for my english and i will tried to repeat anda explain again.

A touch listener is not enough for this use case. You need to

  1. React on event.phase = “began” and “ended” in your touch listener

  2. In your touch listener, update some variable which holds information whether your character is moving

  3. Instead of moving the player in your touch handler, register an enterFrame handler, check the variable from #2, then move the player. Since enterFrame is called continuously for each frame, your character will keep moving until you release the touch

A touch listener is not enough for this use case. You need to

  1. React on event.phase = “began” and “ended” in your touch listener

  2. In your touch listener, update some variable which holds information whether your character is moving

  3. Instead of moving the player in your touch handler, register an enterFrame handler, check the variable from #2, then move the player. Since enterFrame is called continuously for each frame, your character will keep moving until you release the touch