Module: SpriteAnimation

Includes:
SpriteAnimationUtil
Defined in:
lib/sprite_animation.rb,
lib/sprite_animation/version.rb,
lib/sprite_animation/sprite_animation_helper.rb

Defined Under Namespace

Classes: Engine, Railtie

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#animate_sprite(image_src, frame_count, params = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sprite_animation/sprite_animation_helper.rb', line 6

def animate_sprite(image_src, frame_count, params = {})
  scale = params[:scale] || 1

  img_width, img_height = ImageSize.size(image_src).map { |d| d*scale }

  orientation = params[:orientation] ||
    guess_orientation(img_width, img_height)

  frame =
    send(orientation,*[img_width,img_height,frame_count])

  image = image_tag(image_url(image_src), class: "animated",
                    frameCount: frame_count, 
                    frameLength: frame[:length],
                    frameSide: frame[:margin],
                    style: frame[:style])

  (:div, image, 
              style: animated_div_style(frame[:width],frame[:height]))
end