Some systems, such as animated image systems which work by loading several images and cycling them, can benefit from pre-loading these images.
Whenever an image is loaded into the cache, a small freeze will happen. This is barely noticeable on higher end PCs, but on older ones, it is pretty obvious.
If these animated images need to be animated during gameplay, the first few frames of the animation will lower the FPS quite a bit and cause small lag spikes until the full animation cycle is loaded (all images are loaded). The amount of FPS loss depends on the size of the images loaded and the specs of the PC the game runs on.
Pre-loading these images would eliminate the FPS loss on the first animation cycle for them, not to mention that these animated images could potentially start at a later point too (so not during the transition), so it would be especially helpful to pre-load those images to preserve a smooth FPS during the whole gameplay.
Pre-loading the needed animations from the database would also majorly help in games where they are often used. Displaying these animations will always cause a small lag spike when they trigger. Doing this is especially helpful for real-time battle systems which often use animations such as an ABS or some hybrid systems.
Aside from animations, a project without custom scripts would not benefit more from pre-loading assets, but even than, pre-loading the often used animations and keeping them in the cache would make a huge difference in the performance of the game.
Here is an example of writing a loading bar code for images:
Spoiler
class LoadBar
def initialize
@sp = Sprite.new
@sp.bitmap = Bitmap.new(200,40)
@sp.x = (Graphics.width - @sp.bitmap.width) / 2
@sp.y = (Graphics.height - @sp.bitmap.height) / 2
@folder = "Graphics/ParallaxMaps/"
@files = Dir.glob("#{@folder}*.jpg") + Dir.glob("#{@folder}*.png")
@max = @files.size
@loaded = 0
@rate = 0.0
@color = Color.new(255,10,10,255)
update
Graphics.update
p Time.now
@files.each do |fl|
file = fl.sub(@folder,"")
Cache.load_bitmap(@folder,file)
@loaded += 1
update
Graphics.update
end
Graphics.wait(30)
p Time.now
end
def update
@rate = @loaded.to_f / @max
@sp.bitmap.clear
@sp.bitmap.fill_rect(0,30,@rate*200,10,@color)
@sp.bitmap.draw_text(0,0,200,24,sprintf("%1.2f%",@rate*100),1)
end
def dispose
@sp.bitmap.dispose
@sp.dispose
end
end
lbar = LoadBar.new
lbar.dispose
It's really a basic one, but it works well. Shows the progress of loading the specified images to the cache.
I couldn't be bothered to make it dynamic, just threw it together, but add a few arguments here and there, and you can make it load any image from any folder whenever you want, and show it to the user as well.
One thing to note though...
In the case of small image files, doing this will actually slow down the loading process a bit because of the progress bar drawing.
In the case of big files, it still slows it down a bit, but because the load time for bigger files is already kinda long, the slowdown here is barely noticeable.