Class: Chobo::Animation

Inherits:
Object
  • Object
show all
Defined in:
lib/chobo/animation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frames, interval, looping = true) ⇒ Animation

Returns a new instance of Animation.



6
7
8
9
10
11
12
# File 'lib/chobo/animation.rb', line 6

def initialize frames, interval, looping = true
  @frames = frames
  @interval = interval
  @looping = looping
  @state = :running
  reset()
end

Instance Attribute Details

#framesObject

Returns the value of attribute frames.



4
5
6
# File 'lib/chobo/animation.rb', line 4

def frames
  @frames
end

#intervalObject

Returns the value of attribute interval.



4
5
6
# File 'lib/chobo/animation.rb', line 4

def interval
  @interval
end

Instance Method Details

#frameObject



36
37
38
# File 'lib/chobo/animation.rb', line 36

def frame
  @frames[@current_frame]
end

#resetObject



14
15
16
17
18
# File 'lib/chobo/animation.rb', line 14

def reset
  @current = 0.0
  @current_frame = 0
  @state = :running
end

#update(dt) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chobo/animation.rb', line 20

def update dt
  if @state == :running
    @current += dt
    if @current > @interval
      @current_frame += 1
      if @current_frame > @frames.size - 1
        if @looping
          reset()
        else
          @state = :stopped
        end
      end
    end
  end
end