On Thu, Jun 26, 2008 at 12:51:08AM -0400, Tieg Zaharia wrote:
> I was wondering why it's not possible to call animate() inside a keypress
> event? All the typical Shoes shapes seem to work in one, but if you nest an
> animate() loop in there it doesn't work.
> 
> Is animate() mostly intended to encompass whole apps, or is it possible to
> do little animate() parts only when we need them?

What platform are you on?  animate() should be okay in a keypress().

Here's an example that will move a circle when you press a key.  And
then pause it the next time you press a key.

  Shoes.app do
    background white
    @circle = oval 0, 0, 100, 100
  
    keypress do
      if @anim
        @anim.toggle
      else
        @anim = animate do |i|
          @circle.move i, i
        end
      end
    end
  end

One thing you have to remember about using `animate` in a keypress
or mouse event is that it'll create a new animation loop every time
the event goes off.  Jenna's advice of starting the animation
outside the event is good.

It's also possible that your keypress isn't going off due to a form
element.

_why

Reply via email to