Module: Shoes::DSL::Animate

Included in:
Shoes::DSL
Defined in:
shoes-core/lib/shoes/dsl/animate.rb

Instance Method Summary collapse

Instance Method Details

#animate(framerate = 24, opts = {}, &blk) ⇒ Shoes::Animation

Creates an animation that runs the given block of code. Defaults to framerate of 24 frames per second

Examples:

# 10 frames per second
animate 10 do
  # animation code
end

Parameters:

  • framerate (Integer) (defaults to: 24)

    frames per second

  • opts (Hash) (defaults to: {})
  • blk (Proc)

    code to run for each animation frame

Options Hash (opts):

  • :framerate (Integer)

    Frames per second

Returns:



21
22
23
24
# File 'shoes-core/lib/shoes/dsl/animate.rb', line 21

def animate(opts = {}, &blk)
  opts = { framerate: opts } unless opts.is_a? Hash
  Shoes::Animation.new @__app__, opts, blk
end

#every(n = 1, opts = {}, &blk) ⇒ Shoes::Animation

Runs the associated block every N seconds

Parameters:

  • n (Integer) (defaults to: 1)

    run every n seconds

  • blk (Proc)

    code to run each n seconds

Returns:



32
33
34
# File 'shoes-core/lib/shoes/dsl/animate.rb', line 32

def every(n = 1, &blk)
  animate 1.0 / n, &blk
end

#timer(n = 1, opts = {}, &blk) ⇒ Shoes::Timer

Runs the associated block every N seconds

Parameters:

  • n (Integer) (defaults to: 1)

    run every n seconds

  • blk (Proc)

    code to run each n seconds

Returns:



42
43
44
45
# File 'shoes-core/lib/shoes/dsl/animate.rb', line 42

def timer(n = 1, &blk)
  n *= 1000
  Timer.new @__app__, n, &blk
end