The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: ngoaho on January 21, 2010, 03:15:33 AM

Title: Loading Screen
Post by: ngoaho on January 21, 2010, 03:15:33 AM
a script that give a loading screen when transition start
give credit if use
Code: [Select]
#==============================================================================
# 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
Title: Re: Loading Screen
Post by: ngocthang26 on January 21, 2010, 03:14:04 PM
I do not think will meet ngoaho
Title: Re: Loading Screen
Post by: ngoaho on January 22, 2010, 05:36:11 PM
ah, hi ngocthang26, nice to meet you at here
Title: Re: Loading Screen
Post by: ngocthang26 on January 26, 2010, 12:13:31 AM
me too
Title: Re: Loading Screen
Post by: Zylos on January 26, 2010, 01:35:59 AM
What kind of loading screen is this? Can we get a screenshot?
Title: Re: Loading Screen
Post by: Grafikal on January 26, 2010, 01:38:55 AM
Zylos, first you have to say something in gibberish and then translate into their language :)
Title: Re: Loading Screen
Post by: ngoaho on January 27, 2010, 03:55:22 AM
in script
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fc.uploadanh.com%2Fupload%2F2%2F470%2F0.5096401_1_1.jpg&hash=25390781c0fb249e3ca9aa38a0cc9d6f25bbd57e)
loading, you can change loading text each time you load.
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fc.uploadanh.com%2Fupload%2F2%2F470%2F0.5096400_1_1.jpg&hash=17a885b82ae9ddb2247f76a39a94ee06c49b82ec)
load ok, new scene
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fc.uploadanh.com%2Fupload%2F2%2F470%2F0.5096399_1_1.jpg&hash=848cbc04070271769c350dc4229f26bd33b63632)
Title: Re: Loading Screen
Post by: stripe103 on January 30, 2010, 07:20:23 PM
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.
Title: Re: Loading Screen
Post by: stripe103 on February 27, 2010, 06:36:52 PM
BIG BUMP
Title: Re: Loading Screen
Post by: Zeriab on February 28, 2010, 01:37:02 PM
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:
Code: [Select]
#==============================================================================
# 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
Title: Re: Loading Screen
Post by: stripe103 on February 28, 2010, 06:41:57 PM
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)
Title: Re: Loading Screen
Post by: Taylor on March 14, 2010, 02:16:30 AM
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?
Title: Re: Loading Screen
Post by: Grafikal on March 14, 2010, 03:02:55 AM
it doesn't load anything, it's aesthetic which isn't really aesthetic because no one likes loading screens unless you need them.
Title: Re: Loading Screen
Post by: Zeriab on March 14, 2010, 02:00:44 PM
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 (http://rmrk.net/index.php/topic,37177.msg438509.html#msg438509) 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*
Title: Re: Loading Screen
Post by: Taylor on March 19, 2010, 08:29:02 AM
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:
Title: Re: Loading Screen
Post by: ngoaho on April 02, 2010, 02:07:21 PM
long time no visit, thank you zeriab, i forget it.
p/s: i'm looking for a rgss editor, anyone have.
Title: Re: Loading Screen
Post by: max2000 on April 23, 2010, 01:00:41 PM
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:
Title: Re: Loading Screen
Post by: ngoaho on May 13, 2010, 02:57:45 AM
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.