Animation

Creating an animated sprite in H2D is relative easy.

Instead of using h2d.Bitmap to display a single Tile, you can use h2d.Anim to display a list of tiles that will automatically be played:

  1. // creates three tiles with different color
  2. var t1 = h2d.Tile.fromColor(0xFF0000, 30, 30);
  3. var t2 = h2d.Tile.fromColor(0x00FF00, 30, 40);
  4. var t3 = h2d.Tile.fromColor(0x0000FF, 30, 50);
  5. // creates an animation for these tiles
  6. var anim = new h2d.Anim([t1,t2,t3],s2d);

The following properties and methods can be accessed on h2d.Anim:

  • speed : changes the playback speed of the animation, in frames per seconds.
  • loop : tells if the animation will loop after it reaches the last frame.
  • onAnimEnd : this dynamic method can be set to be informed when we have reached the end of the animation :
  1. anim.onAnimEnd = function() {
  2. trace("animation ended!");
  3. }

Anim instances have other properties which can be discovered by reviewing the h2d.Anim class.