Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- -- Code 12a - tween
- -- 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 is a table with three table elements:
- -- x = 100, y = 100, size = 50
- obj = {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, y = HEIGHT, size = 200})
- t2 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
- {loop = tween.loop.pingpong})
- t3 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
- tween.easing.bounceInOut)
- t4 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
- {easing = tween.easing.bounceOutIn,
- loop = tween.loop.pingpong})
- -- t5 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
- -- {tween.easing.bounceOutIn, tween.loop.pingpong})
- t6 = tween(5, obj, {x = WIDTH, y = HEIGHT, size = 200},
- {easing = tween.easing.bounceInOut,
- loop = tween.loop.once}, endIt)
- end
- -- This function gets called once every frame
- function draw()
- -- This sets a dark background color
- background(40, 40, 50)
- -- This sets the line thickness
- strokeWidth(5)
- -- tween.stopAll()
- tween.stop(t1)
- tween.stop(t2)
- tween.stop(t3)
- tween.stop(t4)
- -- tween.stop(t6)
- -- Do your drawing here
- -- Note use of all three table values
- ellipse(obj.x, obj.y, obj.size)
- end
- function endIt()
- print("endIt")
- print("Done")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement