SHARE
TWEET

Code 12a - tween

br1wr2el3 Apr 27th, 2013 249 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. --# Main
  3. -- Code 12a - tween
  4.  
  5. -- Bruce Elliott
  6. -- April 2013
  7.  
  8. -- In App 5b we looked at  creating a tween to move an
  9. -- object from one corner of the screen to the opposite corner.
  10. -- The purpose was to demonstrate the basics of using a tween with and with-out
  11. -- an easing function.
  12.  
  13. -- easing functions add some visual "eye-candy" but the basic idea is still to get
  14. -- from one point to another.
  15.  
  16. -- Take a look at the Codea example program Animation.
  17. -- This demo shows off a lot of features of using tweens
  18. -- My problem is figureing out how to use any of those
  19. -- features in my own code.
  20.  
  21. -- After doing the Appetizer for tweens I have a much better
  22. -- idea of what to do.
  23.  
  24. -- If I understand the process, it involves two basic steps:
  25. -- 1. Set up the tween definition pay attention to parameter two
  26. --    the object table with x and y
  27. -- 2. Use those values in the draw function with the object
  28. --    you want to move, like a circle or a sprite
  29.  
  30. -- In this recipe we will examine many of the features shown
  31. -- in the example. There may be several example programs.
  32.  
  33.  
  34. function setup()
  35.    
  36.     -- obj is a table with three table elements:
  37.     -- x = 100, y = 100, size = 50
  38.     obj = {x = 100, y = 100, size = 50}
  39.    
  40.     -- time = 5 seconds
  41.     -- target is x = width, y = height, and size = 200
  42.     -- loop is inside a table equal to loop type
  43.     t1 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200})
  44.     t2 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
  45.         {loop = tween.loop.pingpong})
  46.     t3 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
  47.         tween.easing.bounceInOut)
  48.     t4 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
  49.         {easing = tween.easing.bounceOutIn,
  50.            loop = tween.loop.pingpong})
  51.  --   t5 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
  52.  --       {tween.easing.bounceOutIn, tween.loop.pingpong})
  53.     t6 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
  54.         {easing = tween.easing.bounceInOut,
  55.             loop = tween.loop.once}, endIt)
  56.    
  57. end
  58.  
  59. -- This function gets called once every frame
  60. function draw()
  61.     -- This sets a dark background color
  62.     background(40, 40, 50)
  63.  
  64.     -- This sets the line thickness
  65.     strokeWidth(5)
  66.  --   tween.stopAll()
  67.     tween.stop(t1)
  68.     tween.stop(t2)
  69.     tween.stop(t3)
  70.     tween.stop(t4)
  71.  --   tween.stop(t6)
  72.     -- Do your drawing here
  73.     -- Note use of all three table values
  74.     ellipse(obj.x, obj.y, obj.size)
  75.    
  76. end
  77.  
  78. function endIt()
  79.     print("endIt")
  80.     print("Done")
  81. 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