Guest User

Untitled

a guest
Dec 21st, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. --This script extends client_anim by providing a set of presets for textlib classes, mimicing the gui presets.
  2. local screenX,screenY = guiGetScreenSize()
  3.  
  4. local function setDXAlpha(dx,alpha)
  5. if type(dx) == 'table' and dx.color then
  6. local r,g,b = dx:color()
  7. dx:color(r,g,b,alpha)
  8. end
  9. end
  10.  
  11. function Animation.presets.dxTextPulse(time, value, phase)
  12. -- dxTextPulse(time)
  13. -- Pulses text (scale down/up). time = ms for a complete pulsation cycle
  14. if type(time) ~= 'table' then
  15. return { from = 0, to = 2*math.pi, transform = math.sin, time = time, repeats = 0, fn = Animation.presets.dxTextPulse }
  16. else
  17. local elem = time
  18. if not phase.scale then
  19. phase.scale = elem:scale()
  20. end
  21. local pct = 1 - (value+1)*0.1
  22. local scale = pct*phase.scale
  23. elem:scale(scale)
  24. end
  25. end
  26.  
  27. function Animation.presets.dxTextFadeIn(time)
  28. return { from = 0, to = 255, time = time or 1000, fn = setDXAlpha }
  29. end
  30.  
  31. function Animation.presets.dxTextFadeOut(time)
  32. return { from = 255, to = 0, time = time or 1000, fn = setDXAlpha }
  33. end
  34.  
  35. function Animation.presets.dxTextMove(endX, endY, time, loop, startX, startY, speedUpSlowDown)
  36. --NB: ABSOLUTE POSITION
  37. -- dxTextMove(endX, endY, [ time = 1000, loop = false, startX = current X, startY = current Y, speedUpSlowDown = false ])
  38. if type(endX) ~= 'table' then
  39. return { from = speedUpSlowDown and -math.pi/2 or 0, to = speedUpSlowDown and math.pi/2 or 1,
  40. time = time or 1000, repeats = loop and 0 or 1, fn = Animation.presets.dxTextMove,
  41. startX = startX, startY = startY, endX = endX, endY = endY, speedUpSlowDown = speedUpSlowDown }
  42. else
  43. local elem, value, phase = endX, endY, time
  44. if phase.speedUpSlowDown then
  45. value = (value + 1)/2
  46. end
  47. if not phase.startX then
  48. phase.startX, phase.startY = elem:position()
  49. if elem.bRelativePosition then
  50. phase.startX, phase.startY = phase.startX*screenX, phase.startY*screenY
  51. end
  52. end
  53. local x = (phase.startX + (phase.endX - phase.startX)*value)/screenX
  54. local y = (phase.startY + (phase.endY - phase.startY)*value)/screenY
  55. elem:position(x,y)
  56. end
  57. end
  58.  
  59. function Animation.presets.dxTextMoveResize(endX, endY, endScale, time, loop, startX, startY, startScale, speedUpSlowDown)
  60. --NB: ABSOLUTE POSITION/SIZE
  61. -- dxTextMoveResize(endX, endY, endScale, [ time = 1000, loop = false, startX = current X, startY = current Y,
  62. -- startScale = currentScale, speedUpSlowDown = false ])
  63. if type(endX) ~= 'table' then
  64. return { from = speedUpSlowDown and -math.pi/2 or 0, to = speedUpSlowDown and math.pi/2 or 1,
  65. time = time or 1000, repeats = loop and 0 or 1, transform = math.sin, fn = Animation.presets.dxTextMoveResize,
  66. startX = startX, startY = startY, startScale = startScale,
  67. endX = endX, endY = endY, endScale = endScale, speedUpSlowDown = speedUpSlowDown }
  68. else
  69. local elem, value, phase = endX, endY, endScale
  70. if phase.speedUpSlowDown then
  71. value = (value + 1)/2
  72. end
  73. if not phase.startX then
  74. phase.startX, phase.startY = elem:position()
  75. if elem.bRelativePosition then
  76. phase.startX, phase.startY = phase.startX*screenX, phase.startY*screenY
  77. end
  78. phase.startScale = elem:scale()
  79. end
  80. local x = (phase.startX + value*(phase.endX - phase.startX))/screenX
  81. local y = (phase.startY + value*(phase.endY - phase.startY))/screenY
  82. elem:position(x,y)
  83. local scale = (phase.startScale + value*(phase.endScale - phase.startScale))
  84. elem:scale(scale)
  85. end
  86. end
Advertisement
Add Comment
Please, Sign In to add comment