How to use multi-line sprite sheet in Craftyjs without manually specifying frames

I just started using craftyjs and ran into a problem.

I have a sprite sheet that has two lines for the same animation. The top row is 4, the bottom is 3.

I can’t figure out how to make him play through all 7 images. I can make him play through one line or another, but not through all.

This is the main function that I have. Check out the comment section. I can make it work fine if I explicitly set each frame. This is not so bad for this, since I only have 7 of them .... but I also have some that have 100+!

function talk(){
   var talker = Crafty.e('2D, Canvas, talk_start, SpriteAnimation');
   /*
    .reel('talk', 1000 ,[ 
       [0,0],[1,0],[2,0],[3,0],
       [0,1],[1,1],[2,1]
     ])
   */
   talker.reel('talk', 1000, 0, 0, 6);
   talker.animate('talk', -1);
}

Is there a way to do this through all the lines on the sprite sheet without having to manually create frames?

Thanks in advance!

+4
1

, Crafty (v0.7.1) .
, , .

function generateReel(fromX, fromY, frameCount, sizeX) {
  var out = [], i;

  if (frameCount >= 0) {
    for (i = 0; i < frameCount; ++i) {
      out.push([fromX, fromY]);

      if (++fromX >= sizeX) {
        fromX = 0;
        fromY++;
      }
    }
  } else {
    for (i = 0; i > frameCount; --i) {
      out.push([fromX, fromY]);

      if (--fromX < 0) {
        fromX = sizeX - 1;
        fromY--;
      }
    }
  }

  return out;
}

document.getElementById('result1').textContent =
  "[[" + generateReel(0, 0, 7, 4).join("] [") + "]]";
document.getElementById('result2').textContent =
  "[[" + generateReel(2, 1, -7, 4).join("] [") + "]]";
<div>Result of generateReel(0, 0, 7, 4):</div>
<div id="result1"></div>
<div>Result of generateReel(2, 1, -7, 4):</div>
<div id="result2"></div>
Hide result
0

All Articles