By jlnr (dev)
Date 2011-07-16 19:14
You should structure your game in a way so that you can efficiently draw only those objects that are on screen. For example, if you have a tiled map, you should loop from the first visible tile in the top left corner of the screen to the lower right corner of the screen, not from 0..width, 0..height.
I think some other people have used spatial hashes for objects that are not aligned on a grid.
With any optimization in Ruby you should be aware that the actual drawing in Gosu is likely very cheap, Gosu can easily draw hundreds or thousands of images in C++. However, every Ruby method call, loop etc. is very costly because Ruby is slow. Try to keep things simple where possible.