Class: Shoes::Animation

Inherits:
Object
  • Object
show all
Includes:
Common::Inspect
Defined in:
shoes-core/lib/shoes/animation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common::Inspect

#inspect, #to_s

Constructor Details

#initialize(opts, &blk) ⇒ Animation

Creates a new Animation.

Parameters:

  • opts (Hash)

    An options hash

  • blk (Proc)

    A block of code to be executed for each animation frame

Options Hash (opts):

  • :framerate (Integer) — default: 24

    The framerate (frames per second)

  • :app (Shoes::App)

    The current Shoes app


15
16
17
18
19
20
21
22
23
# File 'shoes-core/lib/shoes/animation.rb', line 15

def initialize(app, opts, blk)
  @style = opts
  @framerate = @style[:framerate] || 10
  @app = app
  @blk = @app.current_slot.create_bound_block(blk)
  @current_frame = 0
  @stopped = false
  @gui = Shoes.backend_for(self)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app


25
26
27
# File 'shoes-core/lib/shoes/animation.rb', line 25

def app
  @app
end

#blkObject (readonly)

Returns the value of attribute blk


25
26
27
# File 'shoes-core/lib/shoes/animation.rb', line 25

def blk
  @blk
end

#current_frameObject (readonly)

Returns the value of attribute current_frame


25
26
27
# File 'shoes-core/lib/shoes/animation.rb', line 25

def current_frame
  @current_frame
end

#framerateObject (readonly)

Returns the value of attribute framerate


25
26
27
# File 'shoes-core/lib/shoes/animation.rb', line 25

def framerate
  @framerate
end

Instance Method Details

#increment_frameInteger

Increments the current frame by 1

Returns:

  • (Integer)

    The new current frame


54
55
56
# File 'shoes-core/lib/shoes/animation.rb', line 54

def increment_frame
  @current_frame += 1
end

#removeObject


43
44
45
# File 'shoes-core/lib/shoes/animation.rb', line 43

def remove
  @removed = true
end

#removed?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'shoes-core/lib/shoes/animation.rb', line 47

def removed?
  @removed
end

#startObject


27
28
29
# File 'shoes-core/lib/shoes/animation.rb', line 27

def start
  @stopped = false
end

#stopObject


31
32
33
# File 'shoes-core/lib/shoes/animation.rb', line 31

def stop
  @stopped = true
end

#stopped?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'shoes-core/lib/shoes/animation.rb', line 35

def stopped?
  @stopped
end

#toggleObject


39
40
41
# File 'shoes-core/lib/shoes/animation.rb', line 39

def toggle
  @stopped = !@stopped
end