Day 45: Stanford CS193p – Dynamic Animation

Day 45: Stanford CS193p – Dynamic Animation

Screen Shot 2015-06-26 at 2.35.44 AM
lecture 12 – Dynamic Animation

“Physics Based”
Applying animation to the user experience is a great use of this.
For lecture, building a game and having fun.

Set up physics relating animatable objects and let them run until they resolve to stasis
Easily possible to set it up so that stasis never occurs, but that could be performance problem

//Steps
Create a UIDynamicAnimator
Add UIDynamicBehavior to it (gravity, collisions)
Add UIDynamicItem (usually UIViews) to the UIDynamic Behavior
(UIDynamicItem is a protocol which UIView happens to implement)

Create a UIDynamicAnimator:
var animator = UIDynamicAnimator(referenceView: UIView)
if animating views, all views must be in a view hierarchy with referenceView at the top.

Create and add UIDynamicBehavior instances:
let gravity = UIGravityBehavior()
animator.addBehavior(gravity)
or
collider = UICollisionBehavior()
animator.addBehavior(collider)

Then add UIDynamicItems to a UIDynamicBehavior:

Screen Shot 2015-06-26 at 2.45.18 AM

Behaviors:

Screen Shot 2015-06-26 at 2.51.32 AM

UICollisionBehavior:
var collisionMode: UICollisionBehaviorMode

if .Items, then any items you add to a UICollisionBehavior will bounce off each other
if .Boundaries, then add UIBezierPath boundaries for items to bounce off of…
func addBoundaryWithIdentifier(identifier: NSCopying, forPath: UIBezierPath)
func removeBoundaryWithIdentifier(identifier: NSCopying)
var translatesReferenceBoundsIntoBoundary: Bool

UICollisionBehavior

Screen Shot 2015-06-26 at 2.55.07 AM

UISnapBehavior:
init(item: UIDynamicItem, snapToPoint: CGPoint)
imagine four springs at four corners around item
you can control the damping of these “four springs” with var damping: CGFloat

UIPushBehavior:
var mode: UIPushBehaviorMode
var pushDirection: CGVector
or
var angle: CGFloat
var magnitude: CGFloat

if push .Instantaneous, what happens?
it just sits there wasting memory!

UIDynamicItemBehavior:
special “meta” behavior
controls behavior of items asa they affected by other behaviors
any item added to this behavior(with addItem) will be affected by:
var allowsRotation: Bool
var friction: CGFloat
var elasticity: CGFloat
…among others

Can also get info about items with this behavior:
func linearVelocityForItem(UIDynamicItem) -> CGPoint
func addLinearVelocity(CGPoint, forItem: UIDynamicItem)
func angularVelocityForItem(UIDynamicItem) -> CGFloat

multiple UIDynamicItemBehaviors affecting same item(s) is “advanced”

Screen Shot 2015-06-26 at 2.59.35 AM

Screen Shot 2015-06-26 at 3.08.23 AM

Screen Shot 2015-06-26 at 3.25.27 AM

More of what the demo looked like:

Screen Shot 2015-06-26 at 3.25.39 AM

This post is pure note jotting. I will be going over animation in greater detail till I fully get it. I’ve had some experience with animation from building games on my free time, so I understand a chunk of it, but some the finer points are brand new to me. I will for sure be reviewing this over and over again, along with some sources on StackOverFlow.

Advertisements

Published by: Travis Deaton

I studied International Relations at American University, volunteered for various organizations, and now planning to embark on an adventure of a lifetime. More on that is forthcoming. I paint on the side, you can find my work on fineartdeaton.wordpress.com.

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s