Advertisement
br1wr2el3

Code 12b - tween Experiments

Apr 27th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1.  
  2. --# Main
  3. -- Code 12b - tween Experiments
  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, obj1, and obj2 tables with three table elements:
  37. -- (Notice that obj and obj2 are the same)
  38.  
  39. obj = {x = 100, y = 100, size = 50}
  40. obj1 = {x = WIDTH/2, y = HEIGHT/2, size = 100}
  41. obj2 = {x = 100, y = 100, size = 50}
  42.  
  43. -- time = 5 seconds
  44. -- target is x = width, y = height, and size = 200
  45. -- loop is inside a table equal to loop type
  46. -- t1 = tween(5, obj, {x = WIDTH/2, y = HEIGHT/2, size = 100})
  47. -- t2 = tween(5, obj, {x = 100, y = 100, size = 50})
  48. -- t3 = tween(5, obj, obj2)
  49. -- t5 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200})
  50. -- t4 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
  51. -- {loop = tween.loop.pingpong})
  52. -- t6 = tween(5, obj, obj1)
  53.  
  54. -- t3 will never execute in sequence
  55. -- tween.sequence(t1, t4, t3)
  56. -- tween.sequence(t1, t5, t2)
  57. -- After running sequence with t4 I got ping pong
  58. -- even when it was not in the sequence
  59. -- used reset(t4) to disable
  60. -- Sometimes run would not start sequence
  61. -- Finally commented t4 to disable
  62. -- putting first id in seq twice appears to disable all versions
  63. -- using any id twice may not work
  64. end
  65.  
  66. -- This function gets called once every frame
  67. function draw()
  68. -- This sets a dark background color
  69. background(40, 40, 50)
  70. -- tween.reset(t4)
  71. -- This sets the line thickness
  72. strokeWidth(5)
  73.  
  74. -- Do your drawing here
  75. -- Note use of all three table values
  76. ellipse(obj.x, obj.y, obj.size)
  77.  
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement