javascript - How to use multiline sprite sheet in Craftyjs without specifying frames manually -


i've started out using craftyjs , running problem.

i have sprite sheet has 2 rows same animation. top row has 4, bottom has 3.

i can't figure out how play through 7 images. can play through 1 row or other not through them all.

this main function have. note commented out section. can work fine if explicitly set each frame. it's not bad 1 since have 7 of them.... have 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 way make go through rows on sprite sheet without having manually create frames?

thanks in advance!

as far aware there no built-in way in crafty (v0.7.1) this.
however, can make helper function generate these wrap-around reels you.

function generatereel(fromx, fromy, framecount, sizex) {    var out = [], i;      if (framecount >= 0) {      (i = 0; < framecount; ++i) {        out.push([fromx, fromy]);          if (++fromx >= sizex) {          fromx = 0;          fromy++;        }      }    } else {      (i = 0; > 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>


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -