This gem makes it easy adding an animated image given a sprite sheet

gem install sprite_animation -v 0.3.0



Attention please.
I'm still working on documenting it.
There are still no tests whatsoever.
Any contribution would be extremely appreciated.

This gem makes it easy creating animated images in your views given a sprite sheet. Just add it to your project and start animating sprite sheets. SpriteAnimation gem encapsulates all the javascript, jquery and rails logic you need. It was made to be as simple as possible. Try it!


SpriteAnimation gem extends your view helpers with one more method: animate_sprite.

animate_sprite(image_src, frame_count, params = {})


The source of the image, just like in image_tag helper. Can be a local image or a URL of an image.


String with the number of frames that your sprite sheet has.


An optional hash containing the following parameters:

  • scale: Decimal value to resize your frame size. Defaults to 1.
  • orientation: A symbol containing the orientation of your sprite sheet.
    Can be: :vertical or :horizontal. If it's not given, SpriteAnimation will try to guess it based on the height and width of your sprite sheet.


Add this line to your application's Gemfile:

gem 'sprite_animation'

Then run

bundle install

After that, just add the require statement to your application.js

//= require sprite_animation


Using slim-template

= animate_sprite("sample-sheet.png", "10")      # Looks for a sprite sheet located at app/assets/images/ with 10 frames.
= animate_sprite("sample-sheet.png", "10", scale: 0.5)      # Same as above, but reducing the frame size to 50% of the original.
= animate_sprite("horizontal-sheet.png", "10", orientation: :horizontal)    # Forces the orientation to be horizontal
= animate_sprite("http://www.remotesheet.com/sheet.jpg", "12") # Fetches the sprite sheet at the URL and animates it with 12 frames



After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.


Bug reports and pull requests are welcome on GitHub at https://github.com/DanielsLuz/sprite_animation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.


0.3.0 Added infrastructure for rspec tests.