Jump to content
Search Community

jQuery + GSAP + Sprite Plugin

drewbit test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I had a need for controlling a sprite-sheet, with pause, play, and go-to-frame functionality. Also needed practice creating jQuery plugins.

 

The result is jquery.gsap.sprite.js. 

 

Gitub: https://github.com/agrothe/jquery.gsap.sprite

Demo: http://jsbin.com/quvuzo/6/edit?html,js,output

 

Sample Usage:

var mark = $(".mark").sprite({
   frameWidth: 24,
   frameHeight: 70,
   sheetWidth: 120,
   imageSrc:"https://dl.dropboxusercontent.com/u/6801572/marksprite.png"
});

// Pause the sprite
mark.sprite("pause");

// Play the sprite
mark.sprite("play");

// Resume the sprite from where it was paused
mark.sprite("resume");

// Restart the sprite from the beginning
mark.sprite("restart");

// Stop the sprite
mark.sprite("stop");

// Goto first frame (0 indexed) and stop
mark.sprite("seek", 0, true);

// Goto thrid frame (0 indexed) and stop
mark.sprite("seek", 2, true);

// Goto thrid frame (0 indexed) and continue
mark.sprite("seek", 2);

A few advanced features are overrides for TweenMax and TimelineMax libraries, as well as passing in your own Timeline object for maximum control.

 

Comments and suggestions more than welcome.

See the Pen edit?html,js,output by quvuzo (@quvuzo) on CodePen

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...