On Sat, Jan 26, 2008 at 12:51:59PM +0100, Marnix Kok wrote:
> Are there perhaps better ways to go around drawing many objects?

Shoes Murder will come out in April with support for image blocks,
though you'll probably see them in builds sooner than that.
<http://code.whytheluckystiff.net/shoes/roadmap>

So, the image block is a type of canvas that merges a bunch of shapes into a
single object.  Part of the problem with writing games in Shoes is
that it creates objects for every shape, which can slow things down.
I will expose a method for saving these canvases to disk, too, like
Jesse mentioned.

The idea is that you describe a single image object using a block:

  @zr = image do
    rect 0, 0, 20, 10
    rect 10, 10, 20, 10
  end

Now, @zr is a single Tetris piece you can move around which acts
just like an image.  (Probably a raster image, though I'm not sure
yet.)

Going back to the idea of using this to display a moving starfield
quickly, what you do is create an image block that draws a static
starfield:

  @starfield = image do
    @stars.each do |x, y, size|
      star x, y, size
    end
  end

Assume the @stars contains a list of coordinates and sizes that you
update in your animation timer.  You then call @starfield.redraw to
regenerate the image with the new values.  You skip the creation of
all the Shoes objects and are able to limit things to your own
structure: a list of coordinates which is much more compact.

But I could use any more ideas anybody might have for making sprites
and drawing fast and easy without expanding the size of Shoes (which
has already grown too large.)

_why

Reply via email to