when you call image.draw does gosu draw it inmediatly or does it have some kind of pipeline?
I'm asking this because I have an image that is 32x32 and I just draw it repeatly for the whole screen as a background, so it is a lot of draw calls, could it be more efficient if I use rmagick to create an image the size of the window and then just draw that every frame?
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.
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.record(w, h) to solve this - the simplest way to use it is:
# 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
# @cached_image now contains a Gosu::Image with the width and height that was passed to record
@cached_image.draw 0, 0, Z_MAP
Hope that helps.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill