Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Randomized Title Screen

Hello fellow .orgies! I am in request of a modification of scene_title so that upon starting up, it randomizes 1...6 and loads up that title from the titles folder. (i.e. if the randomized variable is 4, it loads 4.png in the title folder). If this is too vague, let me know. It should be fairly simple, but in return I will give you credit, and a shiny new title screen of your choosing. Thank you for any help, and good luck.
 

khmp

Sponsor

Nope it makes perfect sense.

Code:
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  This class performs title screen processing.
#==============================================================================

class Scene_Title
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  Titles = Dir.glob("./Graphics/Titles/*.{bmp,png,jpg}")
  Titles.each_index { |i| Titles[i] = Titles[i].split("/").last }
  #--------------------------------------------------------------------------
  # * Main Processing !OVERRIDE!
  #--------------------------------------------------------------------------
  def main
    # If battle test
    if $BTEST
      battle_test
      return
    end
    # Load database
    $data_actors        = load_data("Data/Actors.rxdata")
    $data_classes       = load_data("Data/Classes.rxdata")
    $data_skills        = load_data("Data/Skills.rxdata")
    $data_items         = load_data("Data/Items.rxdata")
    $data_weapons       = load_data("Data/Weapons.rxdata")
    $data_armors        = load_data("Data/Armors.rxdata")
    $data_enemies       = load_data("Data/Enemies.rxdata")
    $data_troops        = load_data("Data/Troops.rxdata")
    $data_states        = load_data("Data/States.rxdata")
    $data_animations    = load_data("Data/Animations.rxdata")
    $data_tilesets      = load_data("Data/Tilesets.rxdata")
    $data_common_events = load_data("Data/CommonEvents.rxdata")
    $data_system        = load_data("Data/System.rxdata")
    # Make system object
    $game_system = Game_System.new
    # Make title graphic
    @sprite = Sprite.new
    
    begin
      # Make sure the bitmap is decided randomly.
      @sprite.bitmap = RPG::Cache.title(Titles[rand(Titles.size)])
    rescue
      # If it for some reason fails for whatever.
      @sprite.bitmap = RPG::Cache.title($data_system.title_name)
    end
    
    # Make command window
    s1 = "New Game"
    s2 = "Continue"
    s3 = "Shutdown"
    @command_window = Window_Command.new(192, [s1, s2, s3])
    @command_window.back_opacity = 160
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 288
    # Continue enabled determinant
    # Check if at least one save file exists
    # If enabled, make @continue_enabled true; if disabled, make it false
    @continue_enabled = false
    for i in 0..3
      if FileTest.exist?("Save#{i+1}.rxdata")
        @continue_enabled = true
      end
    end
    # If continue is enabled, move cursor to "Continue"
    # If disabled, display "Continue" text in gray
    if @continue_enabled
      @command_window.index = 1
    else
      @command_window.disable_item(1)
    end
    # Play title BGM
    $game_system.bgm_play($data_system.title_bgm)
    # Stop playing ME and BGS
    Audio.me_stop
    Audio.bgs_stop
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of command window
    @command_window.dispose
    # Dispose of title graphic
    @sprite.bitmap.dispose
    @sprite.dispose
  end
end

Code:
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  This class performs the title screen processing.
#==============================================================================

class Scene_Title < Scene_Base
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  Titles = Dir.glob("./Graphics/System/Title*.{bmp,png,jpg}")
  Titles.each_index { |i| Titles[i] = Titles[i].split("/").last }
  #--------------------------------------------------------------------------
  # * Create Title Graphic !OVERRIDE!
  #--------------------------------------------------------------------------
  def create_title_graphic
    @sprite = Sprite.new
    @sprite.bitmap = Cache.system(Titles[rand(Titles.size)])
  end
end

Both of them override a method. In XP its the entire main method which has a high probability of conflict if you are using a Custom Menu System. In VX I just override the create_title_graphic method and that shouldn't be a problem. One last thing, you don't need to name the title screens with numbers. Name them whatever. The script will determine what's in the folder and load an image at random. However the VX version is digging through Graphics/System. So if you have any other graphic in there beside Title screens they are fair game to be loaded as long as they are an image. If you are using VX let me know if that's a problem.

[edit]
As per Mr. Brewmeister's suggestion I altered the VX's method of how it gathers the title screens from the system folder. If you use the VX method the images placed in the System folder that are meant to be Title Screens must be prefixed with the word "Title". For example "TitleFirst", "Title01", "TitleMonkeys".

Good luck with it Necrile! :thumb:
 
I think there is a good chance of conflict with VX, since "System" holds a bunch of things.
Might be better to use...

  Titles = Dir.glob("./Graphics/System/Title*.{bmp,png,jpg}")

in that first line???  That way it catches any file that begins with "Title" (Title1.png, Title2.png, etc...)

With XP, much less chance of an issue since it's a 'Titles' folder only, but it may not hurt to be consistent.

Be Well
 

khmp

Sponsor

That's a much better idea, I will edit the previous post. Originally I thought of just making an entirely new folder for the VX version and using Cache.load_bitmap instead. Thanks for the advice Mr. Brewmeister.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top