
Swiping
By:
lavalevel on
May 8th, 2012 | syntax:
Lua | size: 1.98 KB | hits: 30 | expires: Never
onScreenSwipe = function( event )
local t = event.target
local phase = event.phase
-- local howManyHits = event.numTaps
local minmov = 12 -- Minimum movement that registers
if "began" == phase then
t.isFocus = true
t.x0 = event.x
t.y0 = event.y
elseif ("ended" == phase or "cancelled" == phase) and t.x0 ~= nil and t.y0 ~= nil then
-- print ("Number of taps: " .. event.numTaps)
if (event.x - t.x0) > minmov then -- Swipe right
io.write("\nSWIPE RIGHT!!!! <-----I====================>")
Runtime:dispatchEvent{name='playerHasMoved'}
if npcInFrontOf > 0 then
if currentMap.monsterList[npcInFrontOf].npcPurpose == "quest" or currentMap.monsterList[npcInFrontOf].npcPurpose == "talk" or currentMap.monsterList[npcInFrontOf].npcPurpose == "sell" then
talkToNpc()
else
swingSwordRight()
end
else
swingSwordRight()
end
--haltPlayerInput()
elseif (event.x - t.x0) < -minmov then -- Swipe Left
io.write ("\nSWIPE LEFT!!!! <-----I====================>")
Runtime:dispatchEvent{name='playerHasMoved'}
if npcInFrontOf > 0 then
if currentMap.monsterList[npcInFrontOf].npcPurpose == "quest" or currentMap.monsterList[npcInFrontOf].npcPurpose == "talk" or currentMap.monsterList[npcInFrontOf].npcPurpose == "sell" then
talkToNpc()
else
swingSwordLeft()
end
else
swingSwordLeft()
end
else
Runtime:dispatchEvent{name='playerHasMoved'}
if npcInFrontOf > 0 then
print ("ScreenPressed")
if currentMap.monsterList[npcInFrontOf].npcPurpose == "quest" or currentMap.monsterList[npcInFrontOf].npcPurpose == "talk" or currentMap.monsterList[npcInFrontOf].npcPurpose == "sell" then
talkToNpc()
else
useMagicOrShield()
end
else
useMagicOrShield()
end
-- TalkToNpc()
end
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
return true
end