Main Menu
  • Welcome to The RPG Maker Resource Kit.

Loading Screen

Started by ngoaho, January 21, 2010, 03:15:33 AM

0 Members and 1 Guest are viewing this topic.

ngoaho

a script that give a loading screen when transition start
give credit if use

#==============================================================================
# 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
     bitmap = Bitmap.new(640,50)
     bitmap.font.size = 15
     bitmap.fill_rect(0,0,640,50,$colorlib.black(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
     loop do
       sleep(0.001)
       Graphics.update
     end
   end
 end
 def stop
   @start.exit unless @start.nil?
   @loading_spr.dispose unless @loading_spr.nil?
 end
end
# use:
# def initialize(*args)
#   NowLoading::start([intro text])
# end
# def load_ok
#   NowLoading::stop
# end

ngocthang26

I do not think will meet ngoaho

ngoaho

ah, hi ngocthang26, nice to meet you at here


Zylos

What kind of loading screen is this? Can we get a screenshot?




Grafikal

Zylos, first you have to say something in gibberish and then translate into their language :)

ngoaho

in script

loading, you can change loading text each time you load.

load ok, new scene

stripe103

I've tried several times. I put it in the Scene_Title so it would show that it loads when it starts. The only problem is that when it comes to the line: NowLoading::start("Loading...") the game just exits. Please help me. I would really like this script.

stripe103


Zeriab

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

stripe103

No I don't want to fake anything, but it is good to have because me and a couple of friends are going to make a quite big game(hopefully)

Taylor

Is this really a loading screen though? All I can make of it is a script that turns on or off a string a transparent rectangle.
You have to control when the text should appear and disappear. While I have figured out how to show what is being loaded (by adding multiple calls to the database loading in Scene_Title), shouldn't a real loading screen detect if data is being loaded and automatically activate itself?

Grafikal

it doesn't load anything, it's aesthetic which isn't really aesthetic because no one likes loading screens unless you need them.

Zeriab

You guys obviously don't understand the concept of threads.
Even so I believed that you didn't need to know how to use threads to use this loading screen.
You just need to know that you have to be careful about creating sprites and windows in the main thread.
I am surprised though as I thought the post with the big picture explained how to use it very well.
I am disappointed in you guys. ;9

@stripe: I dunno why it simple exits the game. It sound very strange. Unless you don't do anything afterwards.

*hugs*

Taylor

Nope, I don't understand them. XD; I can see there's something different about this code though.

I just assumed though it would start and close itself before the title. *shrug* No matter, this might be useful for my VX project because sometimes it takes up to 15 seconds to load. D:

ngoaho

#15
long time no visit, thank you zeriab, i forget it.
p/s: i'm looking for a rgss editor, anyone have.

max2000

hi all
it seems i don't know to use this script  :P
i where do i put it (ex:Scene_Menu-Scene_Title) or do i use a new page of script ? :-\
:lol:

ngoaho

hi max2000, put it in a new script page.
follow http://rmrk.net/index.php/topic,37177.msg438509.html#msg438509 to insert a loading screen.