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.

Making a background on the menu screen

How do you put a background image/wallpaper on the menu screen? I don't want it on the Windowskin itself, I just want the background to show behind the translucent windowskins on the menuscreen. I tried fiddling around with the Scene_Menu class, but nothing seems to be working.
 

khmp

Sponsor

Code:
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs menu screen processing.
#==============================================================================

class Scene_Menu
  # The filename of the image you want in the background.
  BACKGROUND_IMAGE = 'menu_background.png'

  alias_method :xava_menubackground_main, :main
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    background = Sprite.new
    background.bitmap = RPG::Cache.picture(BACKGROUND_IMAGE)
    background.opacity = 128

    xava_menubackground_main

    background.bitmap.dispose
    background.dispose
  end
end

Insert an empty section in the script editor above main. Refer to the FAQ of this forum to get a more accurate picture. Paste in this section the code inside the code tags. I made a constant which you will have to change to whatever you named the background image you want to display in the background of the menu.
Code:
BACKGROUND_IMAGE = 'menu_background.png'
After that you should be set. If you have any trouble with let me know I'll help you out.

Good luck with it Xathia Vastar! :thumb:
 

khmp

Sponsor

If the image is named "map-background.png" than that's what you should set the constant too. When the method Cache.picture is called it automatically looks inside the picture folder. That's why we only need the filename and not the path. Now if you had a folder inside the picture folder and the image was in there then you would need to clarify the path.

Hope that helps good luck with it! :thumb:
 

poccil

Sponsor

In my experience, the path should be canonicalized to make it work properly in an encrypted archive.  RGSS will not accept paths like:

Graphics/Windowskins/../Pictures/menu-background.png

However, it can accept such paths if the path is canonicalized to remove the "/../", thus making it to:

Graphics/Pictures/menu-background.png

The following function "canonicalize" will do this:

Code:
def strsplit(str,re)
 ret=[]
 tstr=str
 while re=~tstr
  ret[ret.length]=$~.pre_match
  tstr=$~.post_match
 end
 ret[ret.length]=tstr if ret.length
 return ret
end


def canonicalize(c)
 csplit=strsplit(c,/[\/\\]/)
 pos=-1
 ret=[]
 retstr=""
 for x in csplit
  if x=="."
  elsif x==".."
   if pos>=0
    ret.delete_at(pos) 
    pos-=1
   end
  else
   ret.push(x)
   pos+=1
  end
 end
 for i in 0...ret.length
  retstr+="/" if i>0
  retstr+=ret[i]
 end
 return retstr
end

Afterwards, the load_bitmap method of RPG::Cache (see the help file) can be modified as follows:

Code:
    def self.load_bitmap(folder_name, filename, hue = 0)
      path = folder_name + filename
      # line added
      path=canonicalize(path)
      # line added
      if not @cache.include?(path) or @cache[path].disposed?
        if filename != ""
          @cache[path] = Bitmap.new(path)
        else
          @cache[path] = Bitmap.new(32, 32)
        end
      end
      if hue == 0
        @cache[path]
      else
        key = [path, hue]
        if not @cache.include?(key) or @cache[key].disposed?
          @cache[key] = @cache[path].clone
          @cache[key].hue_change(hue)
        end
        @cache[key]
      end
    end

With these changes, calls like the one below would be acceptable:

RPG::Cache.windowskin("../Graphics/Pictures/menu-background.png")

I hope this helps.
 

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