Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly, you shouldn't use <strong>background-position-x</strong> as it is not widely supported.</p> <p>There are a few options:</p> <p>If your sprite sheet is laid out along one row only you can get away with using just <strong>TweenMax</strong> on it's own like this: </p> <pre><code>var frameWidth = 100, numCols = 12; var steppedEase = new SteppedEase(numCols); TweenMax.to('#selector', 6, {backgroundPosition: '-'+(frameWidth*numCols)+'px 0px', ease:steppedEase, repeat:-1}); </code></pre> <p>If your sprite sheet is in the grid as you described in your question then you are going to have to bring in <strong>TimeLineMax</strong> to join all the tweens together like this:</p> <pre><code>var frameWidth = 100, frameHeight = 100, numCols = 12, numRows = 10; var steppedEase = new SteppedEase(numCols-1); var tl = new TimelineMax({repeat:-1}); for(var i=0;i&lt;numRows;i++){ tl.add( TweenMax.fromTo('#selector', 0.5, { backgroundPosition:'0 -'+(frameHeight*i)+'px'}, { backgroundPosition: '-'+(frameWidth*(numCols-1))+'px -'+(frameHeight*i)+'px', ease:steppedEase} )); } </code></pre> <p>Here are a couple of working fiddles I've created with a random sprite sheets I've found online to show this in action: <a href="http://jsfiddle.net/Boolean/sV5Ug/2/" rel="noreferrer">http://jsfiddle.net/Boolean/sV5Ug/2/</a> and <a href="http://jsfiddle.net/sV5Ug/3/" rel="noreferrer">http://jsfiddle.net/sV5Ug/3/</a></p> <hr> <p>A completely different option is to animate on the canvas using <strong>CreateJS</strong> with <strong>Zoe</strong>. Zoe allows you to export your animation as a sprite sheet and json files from a variety of tools (such as the Flash IDE). You would then use the BitmapAnimation class within CreateJS to turn the spritesheet image and json into an animation.</p> <p>Demos and info here: </p> <p><a href="http://www.createjs.com/#!/EaselJS/demos/spritesheet" rel="noreferrer">http://www.createjs.com/#!/EaselJS/demos/spritesheet</a></p> <p><a href="http://www.createjs.com/#!/Zoe" rel="noreferrer">http://www.createjs.com/#!/Zoe</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload