1. Computing
Send to a Friend via Email

Click Blocks and Animation

By

3 of 5

Getting Animated
Click Blocks and Animation

The animate method will run a block at a set interval. Its single parameter defines the interval at which this method will be called in frames per second. In this example, an animate block at one frame per second will increment a counter and display the result.

More sophisticated uses of animate can include creating actual animation with multiple image objects, implementing flashing text, or doing anything else that requires a timed interval.

Shoes.app :width => 400, :height => 300 do
  @box = stack
  @num = 0

  animate(1) do
    @num += 1
    @box.append para("#{@num}\n")
  end
end
  1. About.com
  2. Computing
  3. Ruby
  4. Graphical User Interfaces
  5. Shoes
  6. Getting Animated

©2014 About.com. All rights reserved.