update_cursor
method. Digging deeper, you call update_string_colors
each time you change index. Now, this method is interesting. Your update colors creates new texts every time, instead of just updating your color. And the texts are actually of Text class, which derives from Gosu::Font. So... every time you change position, you create 5 new texts just to change color, but these texts actually create a new font instance, reading file each time and processing everything. This is... terrible. I hope that this version is really outdated and you fixed the issue, because I can't imagine you thought it's alright.def img(name)
$_images ||= {}
$_images[name] ||= Gosu::Image.new(name)
end
Gosu::Image.new
with img
. This alone cut map transition time by ~3/4. You should make a method to cache tiles too, so you call Image.load_tiles
only ones for each spriteset/size. Basically, the game suffers from bad resource management.Gosu::Font
can be a bit unintuitive because other toolkits cache fonts internally. What Gosu's font does is basically call Gosu::Image.from_text('a'...)
once for each letter that is used, and these letters are then cached per Font
instance. So yeah, don't re-create fonts if you can at all avoid it, otherwise every letter will have to be rendered again.def backdrop(filename) Gosu::Image.new('images/backdrops/' + filename + '.png') end
def backdrop(filename) Cache.images[name = 'images/backdrops/' + filename + '.png'] ||= Gosu::Image.new(name) end
@bgm = Cache.bgm(name)
@bgm = Cache.bgm[name] ||= Gosu::Song.new(name)
def get_font(*args)
@@fonts = {} unless defined?(@@fonts)
@@fonts[args] ||= Gosu::Font.new(*args)
end
def text_width(*args)@font.text_width(*args)end
def height(*args)@font.height(*args)end
def draw(*args)@font.draw(*args)end
super(temp_height, name: @name)
@font = get_font(temp_height, name: @name)
$sprites ||= []
@max.times {|i| x, y = rand(300..1200) - 300, rand(100..808) - 650
y += 1 if y.odd?
$sprites << Sprite_Icon.new(x, y, @names[@type], z: 1050) } if $sprites.empty?
@sprites = $sprites
def increase_xy(nx, ny) @x, @y = (@y.between?(608,660)? [@base_x, @base_y + (@y - 608)] : [@x + nx, @y + ny]) end
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill