Advertisement
lvs

Untitled

lvs
Dec 28th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. local selectedDG = display.newGroup()
  2. local tilesDG = display.newGroup()
  3.  
  4. local function animateTile(target)
  5.     -- target.pos gets the position of the selected tile DG so that
  6.     -- we can pull it out of the tilesDG
  7.     local t = tilesDG[target.pos]
  8.     tilesDG.parent:insert(t)
  9.     t.x, t.y = tilesDG:localToContent(t.x, t.y)
  10.     local targetX = selectedDG.numChildren * (t.width + 2)
  11.     local sx, sy = selectedDG:localToContent(targetX, 0)
  12.     transition.moveTo(t , {
  13.         time        = 1500,
  14.         x           = sx,
  15.         y           = sy,
  16.         transition  = easing.outElastic,
  17.         onComplete = function()
  18.             selectedDG:insert(t)
  19.             t.x, t.y = targetX, 0
  20.         end
  21.         })
  22.        
  23. end
  24.  
  25. -- touch event listener for the tiles
  26. local function handleTileEvent( event )
  27.     local phase = event.phase
  28.     local target = event.target
  29.    
  30.     if not target.selected then
  31.         -- do some stuff
  32.     elseif phase == "ended" then
  33.         -- do some game logic stuff      
  34.         animateTile(target)        
  35.     end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement