Академический Документы
Профессиональный Документы
Культура Документы
gamedesigninitiative
at cornell university
Lecture 12
2D Animation
Animation Basics: The FilmStrip
the
3 Scene Graphs gamedesigninitiative
at cornell university
Anatomy of AnimationNode Class
/**
* Sets the active frame as the given index.
*
* @param frame the index to make the active frame
*/
void AnimationNode::setFrame(int frame) {
this->frame = frame;
int x = (frame % cols)*bounds.size.width; Actual code has
int y = (frame / cols)*bounds.size.height; some minor
bounds.origin.set(x,y); optimizations
setPolygon(bounds);
}
the
4 Scene Graphs gamedesigninitiative
at cornell university
Adjusting your Speed
Do not want to go too fast
1 animation frame = 16 ms
Walk cycle = 8/12 frames
Completed in 133-200 ms
stand
stand2crouch
crouch hop
takeoff float
land
the
11 Scene Graphs gamedesigninitiative
at cornell university
Complex Example: Jumping
stand
Jump Press
stand2crouch
Jump Release
crouch hop
Jump Release
takeoff float
Near Ground
land
the
12 Scene Graphs gamedesigninitiative
at cornell university
Complex Example: Jumping
stand
Transition state
needed to align
the sequences stand2crouch
crouch hop
takeoff float
land
the
13 Scene Graphs gamedesigninitiative
at cornell university
Aside: Sync Kills
the
14 Scene Graphs gamedesigninitiative
at cornell university
The Responsiveness Issue
Tightness of stand
the gameplay Additional delay
preventing jump
stand2crouch
crouch hop
takeoff float
land
the
15 Scene Graphs gamedesigninitiative
at cornell university
Fast Transitions: Crossfade Blending
A B
t = 0.0
bc = tba + (1 t)bb
the
16 Scene Graphs gamedesigninitiative
at cornell university
Fast Transitions: Crossfade Blending
A B
t = 0.3
bc = tba + (1 t)bb
the
17 Scene Graphs gamedesigninitiative
at cornell university
Fast Transitions: Crossfade Blending
A B
t = 0.6
bc = tba + (1 t)bb
the
18 Scene Graphs gamedesigninitiative
at cornell university
Fast Transitions: Crossfade Blending
A B
t = 0.8
bc = tba + (1 t)bb
the
19 Scene Graphs gamedesigninitiative
at cornell university
Fast Transitions: Crossfade Blending
A B
t = 1.0
bc = tba + (1 t)bb
the
20 Scene Graphs gamedesigninitiative
at cornell university
Combining With Animation
A B
the
21 Scene Graphs gamedesigninitiative
at cornell university
Related Concept: Tweening
A B
A B
if (action->isDone()) {
action->release();
action = nullptr;
// Do other clean-up
}
the
25 Scene Graphs gamedesigninitiative
at cornell university
Executing Actions: Transforms
Action* action;
action = RotateBy::create(2.0f, 90.0f);
action->retain(); // Need it for later
sprite->runAction(action);
How long
to spend
…
Tweens
rotation
if (action->isDone()) {
action->release();
action = nullptr;
// Do other clean-up
}
the
26 Scene Graphs gamedesigninitiative
at cornell university
Executing Actions: FilmStrips
Action* action;
Vector<SpriteFrame*> theFrames
auto f1 = SpriteFrame::create(im, rec1)
theFrames->push_back(f1);
…
auto f8 = SpriteFrame::create(im, rec8)
theFrames->push_back(f8);
sprite->runAction(action)
Vector<SpriteFrame*> theFrames
auto f1 = SpriteFrame::create(im, rec1)
theFrames->push_back(f1);
…
auto f8 = SpriteFrame::create(im, rec8) Does not
theFrames->push_back(f8);
tween
Animation* seq = Animation::
createWithSpriteFrames(theFrames,0.1f);
action = Animate::create(seq);
action->retain();
Seconds
sprite->runAction(action)
per frame
// Clean up same as before
the
28 Scene Graphs gamedesigninitiative
at cornell university
Executing Actions: FilmStrips
Action* action;
Vector<SpriteFrame*> theFrames
auto f1 = SpriteFrame::create(im, rec1)
theFrames->push_back(f1);
…
auto f8 = SpriteFrame::create(im, rec8)
theFrames->push_back(f8);
the
32 Scene Graphs gamedesigninitiative
at cornell university
Problem With Decoupled Animation
Action* action;
action = RotateBy::create(2.0f, 90.0f); What if we change our
action->retain(); // Need it for later
mind before 2 seconds?
sprite->runAction(action);
the
33 Scene Graphs gamedesigninitiative
at cornell university
Problems With Decoupled Animation
Action* action;
action = RotateBy::create(2.0f, 90.0f); Compatible: Combine
action->retain(); // Need it for later
sprite->runAction(action); Incompatible: Replace
the
34 Scene Graphs gamedesigninitiative
at cornell university
Problems With Decoupled Animation
Action* action;
action = RotateBy::create(2.0f, 90.0f); Compatible: Combine
action->retain(); // Need it for later
sprite->runAction(action); Incompatible: Replace
the
35 Scene Graphs gamedesigninitiative
at cornell university
Problems With Decoupled Animation
Transform Tweening
Physical Animation
Complete Disaster
the
36 Scene Graphs gamedesigninitiative
at cornell university
Recall: Modular Animation
Break asset into parts
Natural for joints/bodies
Animate each separately
Cuts down on filmstrips
Most steps are transforms
Very natural for tweening
Also better for physics
Several tools to help you
Example: Spriter
Great for visualizing design
the
37 Scene Graphs gamedesigninitiative
at cornell university
Recall: Modular Animation
Break asset into parts
Natural for joints/bodies
Animate each separately
Cuts down on filmstrips
Most steps are transforms
Very natural for tweening
Also better for physics
Several tools to help you
Example: Spriter
Great for visualizing design
the
38 Scene Graphs gamedesigninitiative
at cornell university
Recall: Modular Animation
Break asset into parts
Natural for joints/bodies
Animate each separately
Cuts down on filmstrips
Most steps are transforms
Very natural for tweening
Also better for physics
Several tools to help you
Example: Spriter, Spine
Great for visualizing design
the
39 Scene Graphs gamedesigninitiative
at cornell university
Recall: Modular Animation
Break asset into parts Loose hit
boxes
Natural for joints/bodies
Animate each separately
Cuts down on filmstrips
Most steps are transforms
Very natural for tweening
Also better for physics
Inside hit box can safely
Several tools to help you Transform with duration
Example: Spriter Tween animations
Great for visualizing design Manage multiple actions
the
40 Scene Graphs gamedesigninitiative
at cornell university
Aside: Skinning
the
41 Scene Graphs gamedesigninitiative
at cornell university
Aside: Skinning
the
42 Scene Graphs gamedesigninitiative
at cornell university
Spine Demo
the
43 Scene Graphs gamedesigninitiative
at cornell university
Basic Idea: Bones
the
44 Scene Graphs gamedesigninitiative
at cornell university
Basic Idea: Bones
the
45 Scene Graphs gamedesigninitiative
at cornell university
Basic Idea: Bones
Orientation Sprite
(y-axis) attached
Pivot
(origin)
Creates implicit
coordinate space
the
46 Scene Graphs gamedesigninitiative
at cornell university
Bones are Heirarchical
Child
Parent
the
47 Scene Graphs gamedesigninitiative
at cornell university
Bones are Heirarchical
Transforms
apply to
children
the
48 Scene Graphs gamedesigninitiative
at cornell university
Bones are Heirarchical
Transforms
do not affect
the parent
the
49 Scene Graphs gamedesigninitiative
at cornell university
Recall: Scene Graph Hierarchy
Device/
Screen
Bounded Layer Coordinates
box inside
Coords relative
to parent box the
50 Scene Graphs gamedesigninitiative
at cornell university
Bones are a Scene Graph Visualization
the
51 Scene Graphs gamedesigninitiative
at cornell university
Manage With Multiple State Machines
arms
legs walk
shoot
the
52 Scene Graphs gamedesigninitiative
at cornell university
Manage With Multiple State Machines
Can be independent
or coordinated
arms
legs walk
shoot
the
53 Scene Graphs gamedesigninitiative
at cornell university
Summary
Standard 2D animation is flipbook style
Create a sequence of frames in sprite sheet
Switch between sequences with state machines