Advertisement
lavalevel

Fixing the touch item

Nov 12th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. touchTest= function (event)
  2.  
  3.     local t = event.target
  4.     local phase = event.phase
  5.         if "began" == phase then
  6.             print ("TOUCHED!")
  7.         end
  8.     print ("touch Test!")
  9.     return true
  10.  
  11. end
  12.  
  13.  
  14. onScreenSwipe = function( event )
  15.  
  16.     local t = event.target
  17.     local phase = event.phase
  18.     -- local howManyHits = event.numTaps  
  19.     local minmov = 12   -- Minimum movement that registers
  20.  
  21.     if "began" == phase then
  22.         t.isFocus = true
  23.         t.x0 = event.x
  24.         t.y0 = event.y
  25.  
  26.         print ()
  27.         print ("bookEvent.X:" .. event.x)
  28.         print ("bookEvent.Y:" .. event.y)
  29.         print ("phase = " .. phase )
  30.     elseif ("ended" == phase or "cancelled" == phase) and t.x0 ~= nil and t.y0 ~= nil then
  31.         -- print ("Number of taps: " .. event.numTaps)
  32.  
  33.         if (event.x - t.x0) > minmov then       -- Swipe right
  34.         display.getCurrentStage():setFocus( nil )
  35.         t.isFocus = false  
  36.             --  io.write("\nSWIPE RIGHT!!!!     <-----I====================>")
  37.                
  38.             if npcInFrontOf > 0 then
  39.                 Runtime:dispatchEvent{name='playerHasMoved'}
  40.                 if currentMap.monsterList[npcInFrontOf].npcPurpose == "fight" then
  41.                 swingSwordRight()
  42.                 else
  43.                 talkToNpc()
  44.                 end
  45.             else
  46.                 Runtime:dispatchEvent{name='playerHasMoved'}
  47.                 swingSwordRight()
  48.             end
  49.             --haltPlayerInput()
  50.             t.x0 = nil
  51.             t.y0 = nil
  52.  
  53.         elseif (event.x - t.x0) < -minmov then  -- Swipe Left
  54.         display.getCurrentStage():setFocus( nil )
  55.         t.isFocus = false  
  56.             --io.write ("\nSWIPE LEFT!!!!     <-----I====================>")
  57.            
  58.             if npcInFrontOf > 0 then
  59.                 Runtime:dispatchEvent{name='playerHasMoved'}
  60.                 if currentMap.monsterList[npcInFrontOf].npcPurpose == "fight" then
  61.                 swingSwordLeft()
  62.                 else
  63.                 talkToNpc()
  64.                 end
  65.             else
  66.                 Runtime:dispatchEvent{name='playerHasMoved'}
  67.                 swingSwordLeft()
  68.             end
  69.             t.x0 = nil
  70.             t.y0 = nil
  71.         else   
  72.  
  73.             display.getCurrentStage():setFocus( nil )
  74.             t.isFocus = false  
  75.  
  76.  
  77.             return false
  78.         end
  79.         display.getCurrentStage():setFocus( nil )
  80.         t.isFocus = false    
  81.     end
  82.        
  83.     return true
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement