On Wed, Aug 27, 2008 at 10:00:58AM -0400, Nick Quaranto wrote:
> Hi everyone, over the past few days I've been working on a clone of Snake
> for Shoes. The game is definitely working, and I'd appreciate any feedback
> that you're willing to give. I'm also running into some slowdown issues as
> players get snakes that are pretty huge, and the game seems to run slower as
> someone keeps on playing it. If anyone can help with these issues I'd love
> to pull your changes :)

Hey, great work!  I have a few suggestions for how you can speed
things up.

Probably the way to make things the fastest is to draw on to an
image surface.  This ends up faster because you don't wind up
creating a bunch of Ruby objects for every shape you draw.

Basically, here's how to do it:

  1. In app.rb, change `Field.new(self)` to
     `Field.new(image(400, 400))`.
  2. In field.rb, change [EMAIL PROTECTED] black` to
     [EMAIL PROTECTED] "#000"`.

That just creates a 400px by 400px image surface for you to paint
on.

Now, as alluded, the real reason it's running slow is because Ruby
objects are piling up.  All the old rectangles are still sitting
around every time the snake is drawn.  These need to be cleared out.
(Unless you use an image surface, as shown above.)

So, basically, if you stick with the technique you're using right
now, you'll need to call [EMAIL PROTECTED] every time you repaint and
then redraw all the shapes from there.

_why

Reply via email to