Advertisement
lvs

Non linear path transition

lvs
Oct 31st, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. -- local easing functions
  2. local pow = math.pow
  3. local sin = math.sin
  4. local pi = math.pi
  5. local rand = math.random
  6. local abs = math.abs
  7.  
  8.  
  9. function easeTrow(t, tMax, start, delta, high)
  10.     local x = (t / tMax) - 0.5
  11.     return start + high * 4 * x * x - high + delta * (t / tMax)
  12. end
  13.  
  14.  
  15.  
  16.  
  17. local square = display.newRect( 0, 0, 50, 50 )
  18. square:setFillColor( 255,255,255 )
  19.  
  20. local _W, _H = display.contentWidth, display.contentHeight
  21. local _CX, _CY = _W * 0.5, _H * 0.5
  22.  
  23. square.x = 0
  24. square.y = _H * 0.8
  25.  
  26. local howHighToTrow = _H * 0.5
  27. local trowDuration = 700
  28.  
  29. transition.to( square, { time = trowDuration, x = _W} )
  30. -- try also
  31. -- transition.to( square, { time = trowDuration, x = _W, transition = easing.inQuad} )
  32. transition.to( square, { time = trowDuration, y = _CY, transition = function (a, b, c, d) return easeTrow (a, b, c, d, howHighToTrow) end } )
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement