Hi Jenna,

I'm trying to toss together a simple Neko (cat chasing the mouse) example and this is going to save me a lot of time.

Thanks for sharing!

Eric Miller


Bluebie, Jenna wrote:
Here's what I have so far, fully functional, though not as advanced as your dream, feel free to build on it! Attached is a demo app showing it working. There is some buggyness when closing the window on nonmac's, I don't know why.

class Sprite < Widget
  def initialize opts = {}
    @sizes = {}
    opts.each { |k,v| self.instance_variable_set("@#{k.to_s}", v) }
    reanimate
  end

  attr_reader :stack, :fps, :motion
  def motion=(value); @motion = value; reanimate; end
  def fps=(value); @fps = value; reanimate; end

  def reanimate
    maxSize true
    clear do
      animate(@fps) do
        clear do
          path = nextFrame
          size = @sizes[path]
          @image = image(path)
          @image.style(:margin_left => maxSize[:width] - size.first)
          @image.style(:margin_top => maxSize[:height] - size.last)
        end
      end
    end
  end

  def nextFrame
    @[EMAIL PROTECTED](n = @[EMAIL PROTECTED])
    return n
  end

  def maxSize(cache = true)
    return @maxSize if @maxSize && cache
@images.values.flatten.each { |path| @sizes[path] = $app.imagesize(path) }
    x, y = @sizes.values.transpose.map { |i| i.max }
    @maxSize = {:width => x, :height => y}
  end
end





Reply via email to