I added images of up down right left arrows and called them up, down, left, and right.
–D-Pad–
local motionx = 0
local motiony = 0
local speed = 7
local function stop (event)
if event.phase == “ended” then
motionx = 0
motiony = 0
end
end
local function moveHero(event)
hero.x = hero.x + motionx
hero.y = hero.y + motiony
end
local function goingup(event)
if event.phase == “began” then
motionx = speed
motiony = 0
hero:prepare(“goup”)
hero:play()
end
end
local function goingdown(event)
if event.phase == “began” then
motionx = -speed
motiony = 0
hero:prepare(“godown”)
hero:play()
end
end
local function goingleft(event)
if event.phase == “began” then
motionx = 0
motiony = -speed
hero:prepare(“goleft”)
hero:play()
end
end
local function goingright(event)
if event.phase == “began” then
motionx = 0
motiony = speed
hero:prepare(“goright”)
hero:play()
end
end
up:addEventListener(“touch”, goingup)
down:addEventListener(“touch”, goingdown)
left:addEventListener(“touch”, goingleft)
right:addEventListener(“touch”, goingright)