SHARE
TWEET

Animation in lua With Advanced Macros

TheIncgi Jun 16th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function anim( dur, steppers, post )
  2.   local t = thread.new(function()
  3.     local start = os.millis()
  4.     local stop = start + dur
  5.     while true do
  6.       local p = math.map( os.millis(), start, stop, 0, 1 )
  7.       p = math.min( 1, p )
  8.       for i, s in ipairs( steppers ) do
  9.         s( p )
  10.       end
  11.       if p == 1 then break end
  12.     end
  13.     post()
  14.    
  15.   end)
  16.   t.start()
  17. end
  18.  
  19. hud2D.clearAll()
  20. local text = hud2D.newText("Test", 10, 10)
  21. text.setOpacity(0)
  22. text.enableDraw()
  23.  
  24. local a, b = 5,   25 --arbitrary values
  25. function s1( p )
  26.    text.setX( math.map( p, 0, 1,  a, b) )
  27. end
  28.  
  29. function s2( p )
  30.    text.setOpacity( p^5 )
  31. end
  32.  
  33.  
  34. anim( 1000, {s1, s2}, function() log("Done!") end )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top