SlideShare una empresa de Scribd logo
1 de 44
The enchant.js
Animation Engine
  in 5 Minutes
Introductions

Ryohei Fushimi (@sidestepism)
Ubiquitous Entertainment, Inc. (UEI)
Akihabara Research Center (ARC)
9leap Project Leader

English Translation:
Brandon McInnis (@BrandonUnfathom)
enchant.js Technical Evangelist
If we want to make the bear move...
bear.addEventListener(“enterframe”, function(){
    bear.x ++;
});

// moves the bear to the right by one pixel every frame
He moves!
But he doesn’t stop...
bear.addEventListener(“enterframe”, function(){
    if(bear.x < 100)bear.x ++;
});

// moves the bear to the right by one pixel every frame IF the bear’s position
on the x-axis is less than 100

//(x,y coordinates always start at (0,0) in the upper left-hand corner)
This time...
He stopped!
But...
But...
But...
What about movement like this?
We use
animation.enchant.js
kind of wordy...

          We use
animation.enchant.js
We use
animation.enchant.js
We use
               tl.enchant.js

Note: As of version v0.6, tl.enchant.js is now part of
  the enchant.js main library, and not a separate
plugin. The following examples still work the same
                   way, however.
tl : abbreviation for TimeLine
     We’ll explain this later.
// To move the bear to (120,120) over 30 frames (1
second by the default 30 fps)

bear.tl.moveTo(120, 120, 30);
// First move the bear to (120, 120) over 30 frames,
// then move the bear to (60,180) over 30 frames.

bear.tl.moveTo(120, 120, 30).moveTo(60, 180, 30);
// Move the bear to (120, 120) over 30 frames,
// then move the bear to (60, 180) over 30 frames,
// then move the bear to (180, 90) over 30 frames.

bear.tl.moveTo(120, 120, 30)
    .moveTo(60, 180, 30)
    .moveTo(180, 90, 30);
Order of processing


          moveTo(120, 120, 30)

                                  Representation of
          moveTo(180, 90, 30)
                                    how timeline
                                   commands are
                                 stacked in a queue.
          moveTo(160, 30, 30)
Movement
    Feature #0
               moveTo/moveBy




bear.tl.moveTo(120, 120, 30);
// absolute movement to (120, 120)

bear.tl.moveBy(40, 40, 30);
// relative movement by (+40, +40)
Feature #1        Fade in
                      fadeIn




bear.tl.fadeIn(30);

// fade in over 30 frames
Feature #2     Changing size
                   scaleTo/scaleBy




bear.tl.scaleTo(3, 30);

// scale the bear by a factor of 3 (3x normal size) over 30 frames
Feature #3     Specified time delay
                   delay




bear.tl.delay(30).fadeIn(30);

// wait 30 frames, then fade the bear in over 30 frames
Feature #4     Run a function
                   then




bear.tl.delay(30).then(function(){
    scene.removeChild(bear);
});

// wait 30 frames, then remove the bear from the screen
Feature #5      Run multiple functions
                     cue



bear.tl.cue({
    10: function(){ ... },
    20: function(){ ... },
    30: function(){ ... },
    50: function(){ ... }
});
// execute functions at specified frames (i.e. at 10 frames after
execution, run first function; 20 frames after execution, run second
function; etc.)
Feature #6     Tweening
                   tween


bear.tl.tween({
    x: 120,
    y: 120,
    scaleX: 3,
    scaleY: 3,
    time: 100
});
// perform multiple tl operations simultaneously over 100 frames

// Did you know? The word “tween” comes from the word
“inbetweening,” meaning to create animation frames between two
keyframes. http://en.wikipedia.org/wiki/Inbetweening
Feature #7   Parallel Execution
                 and




bear.tl.fadeIn(30).moveTo(120, 120, 30)
// fade in over 30 frames, and then move to (120,120) over
30 frames

bear.tl.fadeIn(30).and().moveTo(120, 120, 30)
// fade in over 30 frames and move to (120,120) over 30
frames simultaneously!
Feature #8   loops
                 loop




bear.tl.fadeIn(30).fadeOut(30).loop();
// loop an animation of fading in over 30 frames, and then
fading out over 30 frames
Feature #9   Fast-forward
                 skip




bear.tl.skip(100);

// fast-forward by 100 frames
Feature#10 Execute a function repeatedly
             repeat




Feature#11   Pause/resume the queue
             pause / resume




Feature#12 Erase the entire queue
             clear
Execute a function, wait for it to complete,
Feature#13   and then move on
             waitUntil




Feature#14 Define an action
             action




Feature#15 Erase from a scene
             removeFromScene
Feature#16    Time-based animation
                  setTimeBased

bear.tl.setTimeBased();
bear.tl.fadeIn(3000)

// make all tl animation functions accept duration values
in milliseconds instead of frames, then fade in the bear
over 3000 ms (3 seconds)

// this can be reversed with setFrameBased();

// for more information on time-based animation with
enchant.js, see Kevin Kratzer’s tutorial at
http://bit.ly/XcLHDC
You must remember
  EASING
If the rate at which a sprite moves
        changes over time...
this is called EASING!
       If this is confusing, please see the first part of
http://bit.ly/109CYbP for an explanation of the concept of
                 easing, using Lego animation.
// Easing

bear.tl.moveTo(120, 120, 30, enchant.Easing.QUAD_EASEINOUT);

bear.tl.tween({
   x: 120,                               Specify via a
   y: 120,                                 function
   scaleX: 3,
   scaleY: 3,
   time: 100,
   easing: enchant.Easing.QUAD_EASEINOUT
}));
Several preset easing functions can be chosen
                    from.



                       QUAD_
                       QUBIC_
                       QUINT_
                       SIN_         EASEIN
     enchant.Easing.   BACK_      + EASEOUT
                       CIRC_
                       ELASTIC_     EASEINOUT
                       BOUNCE_
                       EXPO_
The Tweener Transition Cheat Sheet
        http://bit.ly/3u7B6
    explains these movements
As you can see, many different functions and
 features exist for animation and timelines in
     the animation engine of enchant.js.
Check it out on github if you haven’t already!
The enchant.js
animation engine

Más contenido relacionado

Similar a The Enchant.js Animation Engine in 5 Minutes

다음웹툰의 UX(Animation, Transition, Custom View)
다음웹툰의 UX(Animation, Transition, Custom View)다음웹툰의 UX(Animation, Transition, Custom View)
다음웹툰의 UX(Animation, Transition, Custom View)if kakao
 
Intro to Python (High School) Unit #3
Intro to Python (High School) Unit #3Intro to Python (High School) Unit #3
Intro to Python (High School) Unit #3Jay Coskey
 
Макс Грибов — Использование SpriteKit в неигровых приложениях
Макс Грибов — Использование SpriteKit в неигровых приложенияхМакс Грибов — Использование SpriteKit в неигровых приложениях
Макс Грибов — Использование SpriteKit в неигровых приложенияхCocoaHeads
 
Александр Зимин – Анимация как средство самовыражения
Александр Зимин – Анимация как средство самовыраженияАлександр Зимин – Анимация как средство самовыражения
Александр Зимин – Анимация как средство самовыраженияCocoaHeads
 
NTU ML TENSORFLOW
NTU ML TENSORFLOWNTU ML TENSORFLOW
NTU ML TENSORFLOWMark Chang
 
Tensor flow description of ML Lab. document
Tensor flow description of ML Lab. documentTensor flow description of ML Lab. document
Tensor flow description of ML Lab. documentjeongok1
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Programação assíncrona utilizando Coroutines
Programação assíncrona utilizando CoroutinesProgramação assíncrona utilizando Coroutines
Programação assíncrona utilizando CoroutinesDiego Gonçalves Santos
 
Open GL Animation
Open GL  AnimationOpen GL  Animation
Open GL AnimationKiran Munir
 
Randomising css animations
Randomising css animationsRandomising css animations
Randomising css animationsasjb
 
The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180Mahmoud Samir Fayed
 
Crafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David OrtinauCrafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David OrtinauXamarin
 
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando CoroutinesTDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutinestdc-globalcode
 
Expand/Collapse animation on Android
Expand/Collapse animation on AndroidExpand/Collapse animation on Android
Expand/Collapse animation on AndroidPavlo Dudka
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 
Animation in Java
Animation in JavaAnimation in Java
Animation in JavaAlan Goo
 

Similar a The Enchant.js Animation Engine in 5 Minutes (20)

14709302.ppt
14709302.ppt14709302.ppt
14709302.ppt
 
다음웹툰의 UX(Animation, Transition, Custom View)
다음웹툰의 UX(Animation, Transition, Custom View)다음웹툰의 UX(Animation, Transition, Custom View)
다음웹툰의 UX(Animation, Transition, Custom View)
 
Intro to Python (High School) Unit #3
Intro to Python (High School) Unit #3Intro to Python (High School) Unit #3
Intro to Python (High School) Unit #3
 
Макс Грибов — Использование SpriteKit в неигровых приложениях
Макс Грибов — Использование SpriteKit в неигровых приложенияхМакс Грибов — Использование SpriteKit в неигровых приложениях
Макс Грибов — Использование SpriteKit в неигровых приложениях
 
Александр Зимин – Анимация как средство самовыражения
Александр Зимин – Анимация как средство самовыраженияАлександр Зимин – Анимация как средство самовыражения
Александр Зимин – Анимация как средство самовыражения
 
Angular animate
Angular animateAngular animate
Angular animate
 
NTU ML TENSORFLOW
NTU ML TENSORFLOWNTU ML TENSORFLOW
NTU ML TENSORFLOW
 
Tensor flow description of ML Lab. document
Tensor flow description of ML Lab. documentTensor flow description of ML Lab. document
Tensor flow description of ML Lab. document
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
Programação assíncrona utilizando Coroutines
Programação assíncrona utilizando CoroutinesProgramação assíncrona utilizando Coroutines
Programação assíncrona utilizando Coroutines
 
Open GL Animation
Open GL  AnimationOpen GL  Animation
Open GL Animation
 
Randomising css animations
Randomising css animationsRandomising css animations
Randomising css animations
 
The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180
 
Crafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David OrtinauCrafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David Ortinau
 
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando CoroutinesTDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
 
Corona sdk
Corona sdkCorona sdk
Corona sdk
 
Expand/Collapse animation on Android
Expand/Collapse animation on AndroidExpand/Collapse animation on Android
Expand/Collapse animation on Android
 
Animations & swift
Animations & swiftAnimations & swift
Animations & swift
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
Animation in Java
Animation in JavaAnimation in Java
Animation in Java
 

The Enchant.js Animation Engine in 5 Minutes

  • 2. Introductions Ryohei Fushimi (@sidestepism) Ubiquitous Entertainment, Inc. (UEI) Akihabara Research Center (ARC) 9leap Project Leader English Translation: Brandon McInnis (@BrandonUnfathom) enchant.js Technical Evangelist
  • 3. If we want to make the bear move...
  • 4. bear.addEventListener(“enterframe”, function(){ bear.x ++; }); // moves the bear to the right by one pixel every frame
  • 7. bear.addEventListener(“enterframe”, function(){ if(bear.x < 100)bear.x ++; }); // moves the bear to the right by one pixel every frame IF the bear’s position on the x-axis is less than 100 //(x,y coordinates always start at (0,0) in the upper left-hand corner)
  • 13. What about movement like this?
  • 15. kind of wordy... We use animation.enchant.js
  • 17. We use tl.enchant.js Note: As of version v0.6, tl.enchant.js is now part of the enchant.js main library, and not a separate plugin. The following examples still work the same way, however.
  • 18. tl : abbreviation for TimeLine We’ll explain this later.
  • 19. // To move the bear to (120,120) over 30 frames (1 second by the default 30 fps) bear.tl.moveTo(120, 120, 30);
  • 20. // First move the bear to (120, 120) over 30 frames, // then move the bear to (60,180) over 30 frames. bear.tl.moveTo(120, 120, 30).moveTo(60, 180, 30);
  • 21. // Move the bear to (120, 120) over 30 frames, // then move the bear to (60, 180) over 30 frames, // then move the bear to (180, 90) over 30 frames. bear.tl.moveTo(120, 120, 30) .moveTo(60, 180, 30) .moveTo(180, 90, 30);
  • 22. Order of processing moveTo(120, 120, 30) Representation of moveTo(180, 90, 30) how timeline commands are stacked in a queue. moveTo(160, 30, 30)
  • 23. Movement Feature #0 moveTo/moveBy bear.tl.moveTo(120, 120, 30); // absolute movement to (120, 120) bear.tl.moveBy(40, 40, 30); // relative movement by (+40, +40)
  • 24. Feature #1 Fade in fadeIn bear.tl.fadeIn(30); // fade in over 30 frames
  • 25. Feature #2 Changing size scaleTo/scaleBy bear.tl.scaleTo(3, 30); // scale the bear by a factor of 3 (3x normal size) over 30 frames
  • 26. Feature #3 Specified time delay delay bear.tl.delay(30).fadeIn(30); // wait 30 frames, then fade the bear in over 30 frames
  • 27. Feature #4 Run a function then bear.tl.delay(30).then(function(){ scene.removeChild(bear); }); // wait 30 frames, then remove the bear from the screen
  • 28. Feature #5 Run multiple functions cue bear.tl.cue({ 10: function(){ ... }, 20: function(){ ... }, 30: function(){ ... }, 50: function(){ ... } }); // execute functions at specified frames (i.e. at 10 frames after execution, run first function; 20 frames after execution, run second function; etc.)
  • 29. Feature #6 Tweening tween bear.tl.tween({ x: 120, y: 120, scaleX: 3, scaleY: 3, time: 100 }); // perform multiple tl operations simultaneously over 100 frames // Did you know? The word “tween” comes from the word “inbetweening,” meaning to create animation frames between two keyframes. http://en.wikipedia.org/wiki/Inbetweening
  • 30. Feature #7 Parallel Execution and bear.tl.fadeIn(30).moveTo(120, 120, 30) // fade in over 30 frames, and then move to (120,120) over 30 frames bear.tl.fadeIn(30).and().moveTo(120, 120, 30) // fade in over 30 frames and move to (120,120) over 30 frames simultaneously!
  • 31. Feature #8 loops loop bear.tl.fadeIn(30).fadeOut(30).loop(); // loop an animation of fading in over 30 frames, and then fading out over 30 frames
  • 32. Feature #9 Fast-forward skip bear.tl.skip(100); // fast-forward by 100 frames
  • 33. Feature#10 Execute a function repeatedly repeat Feature#11 Pause/resume the queue pause / resume Feature#12 Erase the entire queue clear
  • 34. Execute a function, wait for it to complete, Feature#13 and then move on waitUntil Feature#14 Define an action action Feature#15 Erase from a scene removeFromScene
  • 35. Feature#16 Time-based animation setTimeBased bear.tl.setTimeBased(); bear.tl.fadeIn(3000) // make all tl animation functions accept duration values in milliseconds instead of frames, then fade in the bear over 3000 ms (3 seconds) // this can be reversed with setFrameBased(); // for more information on time-based animation with enchant.js, see Kevin Kratzer’s tutorial at http://bit.ly/XcLHDC
  • 37. If the rate at which a sprite moves changes over time...
  • 38. this is called EASING! If this is confusing, please see the first part of http://bit.ly/109CYbP for an explanation of the concept of easing, using Lego animation.
  • 39. // Easing bear.tl.moveTo(120, 120, 30, enchant.Easing.QUAD_EASEINOUT); bear.tl.tween({ x: 120, Specify via a y: 120, function scaleX: 3, scaleY: 3, time: 100, easing: enchant.Easing.QUAD_EASEINOUT }));
  • 40. Several preset easing functions can be chosen from. QUAD_ QUBIC_ QUINT_ SIN_ EASEIN enchant.Easing. BACK_ + EASEOUT CIRC_ ELASTIC_ EASEINOUT BOUNCE_ EXPO_
  • 41. The Tweener Transition Cheat Sheet http://bit.ly/3u7B6 explains these movements
  • 42. As you can see, many different functions and features exist for animation and timelines in the animation engine of enchant.js.
  • 43. Check it out on github if you haven’t already!