Class: Tatty::Anim

Inherits:
Object
  • Object
show all
Defined in:
lib/tatty/anim.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atlas, width:, height:, **kargs) ⇒ Anim

Returns a new instance of Anim.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tatty/anim.rb', line 9

def initialize(atlas, width:, height:, **kargs)
  @atlas = atlas
  @rate = kargs[:speed] || 2
  @loop = kargs[:loop] || false
  if kargs[:loop_for].nil?
    @loop_for = -1
  else
    @loop = false
    @loop_for_start = kargs[:loop_for] || -1
    @loop_for = @loop_for_start
  end
  @name = kargs[:name]
  @width = width
  @height = height
  reset
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



3
4
5
# File 'lib/tatty/anim.rb', line 3

def height
  @height
end

#loopObject (readonly)

Returns the value of attribute loop.



3
4
5
# File 'lib/tatty/anim.rb', line 3

def loop
  @loop
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/tatty/anim.rb', line 3

def name
  @name
end

#rateObject (readonly)

Returns the value of attribute rate.



3
4
5
# File 'lib/tatty/anim.rb', line 3

def rate
  @rate
end

#widthObject (readonly)

Returns the value of attribute width.



3
4
5
# File 'lib/tatty/anim.rb', line 3

def width
  @width
end

Class Method Details

.from_atlas(filepath, name: :default) ⇒ Object



5
6
7
# File 'lib/tatty/anim.rb', line 5

def self.from_atlas(filepath, name: :default)
  Atlas.new(filepath)[name]
end

Instance Method Details

#displayObject



42
43
44
# File 'lib/tatty/anim.rb', line 42

def display
  @atlas[rate_frame]
end

#nextObject



46
47
48
49
# File 'lib/tatty/anim.rb', line 46

def next
  step
  display
end

#resetObject



26
27
28
29
# File 'lib/tatty/anim.rb', line 26

def reset
  @frame = 0
  @loop_for = @loop_for_start if @loop_for == 0
end

#stepObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/tatty/anim.rb', line 31

def step
  @frame += 1
  if rate_frame >= @atlas.count
    reset if self.loop
    @loop_for -= 1 if @loop_for > 0
    true
  else
    false
  end
end