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)
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...
where 'window' is your Gosu::Window instance
Thank you good sir, this works like a charm. :)
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|….
Thanks, I didn't know that. :) Ruby is full of little surprises like this.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill