Hi ngoaho
It's nice seeing an actual loading script and not one of the fake loading screen which does nothing for a while.
Am I correct in assuming that $colorlib.black(150) is Color.new(0,0,0,150)?
Either way I suggest that you replace $colorlib.black(150) with the corresponding color since $colorlib is
nil in the default scripts.
I suggest that you send a signal to the thread which then takes care of shutting down properly.
Here is a modification of the script showing you what I mean:
#==============================================================================
# Now Loading
# a script that give a loading screen when transition start
# writen by: ngoa ho
# http://www.ngoaho.net- ngoaho91@yahoo.com.vn
#==============================================================================
module NowLoading
module_function
def start(text="§ang t¶i...")
@start = Thread.new do
# Create sprite
bitmap = Bitmap.new(640,50)
bitmap.font.size = 15
bitmap.fill_rect(0,0,640,50,Color.new(0,0,0,150))
bitmap.draw_text(0,0,640,50,text,1)
@loading_spr = Sprite.new
@loading_spr.bitmap = bitmap
@loading_spr.y = 205
@loading_spr.z = 9999
# Wait
loop do
Graphics.update
sleep(1)
# Stop waiting if the loading is done
break if Thread.current[:done] == true
end
# Clean up
@loading_spr.dispose
end
end
def stop
if !@start.nil? && @start.alive?
# Tell the thread that it should stop
@start[:done] = true
# Wakes the thread so we don't have to wait for the sleep
@start.wakeup
# Wait for the thread to finish
@start.join
end
end
end
Notice that I have changed sleep(0.001) to sleep(1). Since it has no animation there is no reason to call Graphics.update so often.
All threads pause when Graphics.update is called. So the fewer calls the better.
I suggest making it animated:
1. Loading
2. Loading.
3. Loading..
4. Loading...
1. Loading
It will give people a feeling of something happening.
Perhaps a sleep(0.4) will feel better for the animation. Maybe more, maybe less.
You should note that creating sprites in the main thread while the loading thread is running is dangerous due to potential race conditions. I.e. Sprite creation is not thread-safe.
@stripe103:
Do you really need this script?
I tried using the script for loading the database in the default scripts. The loading bar flashed and was gone.
Remember that this is an actual loading script. It involves multithreading and thus should only be used if you have a real need for it.
If you just want to fake it I suggest using one of the many of them out there.
*hugs*
- Zeriab