Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- -- Code 12b - tween Experiments
- -- Bruce Elliott
- -- April 2013
- -- In App 5b we looked at creating a tween to move an
- -- object from one corner of the screen to the opposite corner.
- -- The purpose was to demonstrate the basics of using a tween with and with-out
- -- an easing function.
- -- easing functions add some visual "eye-candy" but the basic idea is still to get
- -- from one point to another.
- -- Take a look at the Codea example program Animation.
- -- This demo shows off a lot of features of using tweens
- -- My problem is figureing out how to use any of those
- -- features in my own code.
- -- After doing the Appetizer for tweens I have a much better
- -- idea of what to do.
- -- If I understand the process, it involves two basic steps:
- -- 1. Set up the tween definition pay attention to parameter two
- -- the object table with x and y
- -- 2. Use those values in the draw function with the object
- -- you want to move, like a circle or a sprite
- -- In this recipe we will examine many of the features shown
- -- in the example. There may be several example programs.
- function setup()
- -- obj, obj1, and obj2 tables with three table elements:
- -- (Notice that obj and obj2 are the same)
- obj = {x = 100, y = 100, size = 50}
- obj1 = {x = WIDTH/2, y = HEIGHT/2, size = 100}
- obj2 = {x = 100, y = 100, size = 50}
- -- time = 5 seconds
- -- target is x = width, y = height, and size = 200
- -- loop is inside a table equal to loop type
- -- t1 = tween(5, obj, {x = WIDTH/2, y = HEIGHT/2, size = 100})
- -- t2 = tween(5, obj, {x = 100, y = 100, size = 50})
- -- t3 = tween(5, obj, obj2)
- -- t5 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200})
- -- t4 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
- -- {loop = tween.loop.pingpong})
- -- t6 = tween(5, obj, obj1)
- -- t3 will never execute in sequence
- -- tween.sequence(t1, t4, t3)
- -- tween.sequence(t1, t5, t2)
- -- After running sequence with t4 I got ping pong
- -- even when it was not in the sequence
- -- used reset(t4) to disable
- -- Sometimes run would not start sequence
- -- Finally commented t4 to disable
- -- putting first id in seq twice appears to disable all versions
- -- using any id twice may not work
- end
- -- This function gets called once every frame
- function draw()
- -- This sets a dark background color
- background(40, 40, 50)
- -- tween.reset(t4)
- -- This sets the line thickness
- strokeWidth(5)
- -- Do your drawing here
- -- Note use of all three table values
- ellipse(obj.x, obj.y, obj.size)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement