Simple thing about continuously move something

Here is my code

[lua]local w = display.contentWidth

local h = display.contentHeight

local Player = display.newRect (15, 15, 15, 15)
Player.x = w * 0.5
Player.y = h * 0.5

local Leftbtn = display.newRect (35, 35, 35, 35)
Left.x = w * 0.1
Left.y = h * 1

function moveLeft (event)
     if Player.x > w * 0.3 then
          Player.x = Player.x - 10
     end
end

     

Leftbtn:addEventListener (“touch”, moveLeft)
[/lua]

My question is

How to move my Player continuously when i press and hold the leftbtn.

Because when i hold the leftbtn now, it only move once and need me to press again to move.

What should I change if i want my Player move smoothly like someone walking.

Hi,

 You can create an enterFrame event on another function and run that function when moveLeft function is triggered.e.g.:

Local function giveItAName () Player = Player.x - 10 -- Or try a plus sign to move it in the other direction. end local function moveLeft (event) if event.phase == "began" then Runtime:addEventListener("enterFrame",giveItAName) elseif event.phase == "ended" Runtime:removeEventListener("enterFrame",giveItAName) end end 
  1. Leftbtn:addEventListener (“touch”, moveLeft)

Try something like that,and improove my method.Hope this helps you.

Hi,

 You can create an enterFrame event on another function and run that function when moveLeft function is triggered.e.g.:

Local function giveItAName () Player = Player.x - 10 -- Or try a plus sign to move it in the other direction. end local function moveLeft (event) if event.phase == "began" then Runtime:addEventListener("enterFrame",giveItAName) elseif event.phase == "ended" Runtime:removeEventListener("enterFrame",giveItAName) end end 
  1. Leftbtn:addEventListener (“touch”, moveLeft)

Try something like that,and improove my method.Hope this helps you.