Why don't you try using Benchmark? It will tell you what is the fastest solution, make an example script, making sure you placed some require '.benchmark' on top of it and later call both kind of methods, perhaps one first and later the other one using Benchmark.real_time method. It will tell you how many seconds or milliseconds it took to make gosu draw them.
By jlnr (dev)
Date 2017-09-01 07:23
Gosu uses a pipeline so that it can implement Z-ordering, but this doesn't really affect performance here because the bottleneck is usually the game (Ruby), not Gosu (C++).
If you want to fill a full HD screen with 32x32 tiles, you'll need to call Image#draw 60*34=2040 times. The loop itself, with all the necessary calculations, can indeed be slow. You could use RMagick, but it's unwieldy and hard to install for anyone who wants to play your game.
Gosu offers Gosu.record(w, h)
to solve this - the simplest way to use it is:
class SomeGridClass
def draw
# Only set this instance variable the first time this code is run...
@cached_image ||= Gosu.record(width * 32, height * 32) do
32.times do |y|
32.times do |x|
@some_tile.draw x * 32, y * 32, 0
end
end
end
# @cached_image now contains a Gosu::Image with the width and height that was passed to record
@cached_image.draw 0, 0, Z_MAP
end
...
Hope that helps.