Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / what happens when you call draw?
- - By zenit Date 2017-08-30 11:34
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?
Parent - By kyonides Date 2017-08-31 17:40
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.
Parent - 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.
Up Topic Gosu / Gosu Exchange / what happens when you call draw?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill