Help needed to create a sprite animator script (animated PNG)

Help needed to create a sprite animator script (animated PNG)

 Hi,

I would like to create a sprite animator using Jquery in order to create animated PNGs.



  A sprite is a group of images "glued" together to make a large one.
We create the illusion of movement while moving into that big image in a smaller div (with overflow set to "hidden") used as a mask.





For exemple, I glued together 60 png images organized into 4 columns and 15 rows.
That big image is 400 pixels large and 3000 pixels long (so each images into that sprite is 100px x 200px)


  1. First I have to create a div how is 100x200px (class=image_mask)
  2. In that div I add the sprite and I set display to "none"
  3. Using Jquery, I preload the sprite
  4. Again with Jquery we get the size of the sprite and we make some math :
    1. We get the width = 400 and the height = 3000
    2. We get the size of the image_mask used to embbed the sprite (width: 100px; height: 200px)
    3. We guess the number of images into the sprite -> (400/100)*(3000/200) -> 4(columns)*15(rows) -> 60 images
    4. We move frame to frame using a delay
    5. If we decide to use a loop (infinite or defined), when we get to the 60's image, we go back to the first frame and we do it again.
  
  1.  <style type="text/css">
  2. .image_mask {
  3. position: relative;
  4. width: 100px;
  5. height: 200px;
  6. overflow: hidden;
  7. }
  8. .image_mask img {
  9. position: absolute;
  10. top:0px;
  11. left:0px;
  12. }
  13. </style>
    
  1. <div class="image_mask">
  2. <img src="path/to/mysprite.png" />
  3. </div>


Can we make a function using Jquery to make it happend?

animateMe(".image_mask", 30, 0);

animateMe("mask class or ID", frame rate, loop);
If loop == 0; -> Infinite
If loop is not defined, do not loop the animation

Thanks a lot!

PS: Forgive my english, I hope you will understand what i mean ^^