Hey there,
I'm fairly new to Gosu and Ruby, but I already gathered some experience in the C-Family, Python and Java.
Right now I'm playing around a bit, trying to hack a small Roguelike together using Gosu and Ruby 1.9.
The current problem I'm experiencing is, that my program is slowing down very fast when I try to draw a map using many rectangles. The code is as follows:
for i in 0..@map.width-1
for j in 0..@map.height-1
draw_quad(x, y, 0xffffffff, x+width, y, 0xffffffff, x, y+height, 0xffffffff, x+width, y+height, 0xffffffff, 0)
end
end
Unncessery bits removed.
So is there some kind of way of drawing the rectangle only once, then refering to it and just "blit" it to the screen or something?
Many thanks in advance. :)
On the beginning
rectangle = window.record do
your drawing code...
end
where 'window' is your Gosu::Window instance
and then
rectangle.draw(x,y,z)
By Askr
Date 2013-07-12 06:50
Thank you good sir, this works like a charm. :)
By jlnr (dev)
Date 2013-07-11 22:44
What lol_o2 said :) FWIW, draw_quad
is not the problem, but all the Ruby code around it (loops, calculations).
Ruby mini hint: …
(one dot more) is "up to but not including", so you could rewrite the for
loops as for i in 0…@map.width
. Or you could use @map.width.times do |x|…
.
By Askr
Date 2013-07-12 06:50
Thanks, I didn't know that. :) Ruby is full of little surprises like this.
Loading...