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.

[VX] Pause Game

Pause Game
by Dargor
Version 1.1


Introduction

Another script I made for the FFVI SDK but this version is a lot more customizable!
This script let you pause the game (duh!). And when I say pause the game, I mean EVERYTHING is paused; animations, playtime/frame count, windows, etc.

Features
  • Determine which scenes can be paused
  • Change Graphics brightness when paused
  • Change BGM volume when paused
  • Customizable Pause key
  • Can have a Pause window

Script

Code:
#==============================================================================

# ** Pause Game

#------------------------------------------------------------------------------

#  © Dargor, 2008

#  17/06/08

#  Version 1.0

#------------------------------------------------------------------------------

#  VERSION HISTORY:

#   - 1.0 (17/05/08), Initial release

#   - 1.1 (17/05/08), Added "Stack Reset" prevention

#------------------------------------------------------------------------------

#  INSTRUCTIONS:

#   - Paste this above main

#   - Edit the constants in the Pause_Game module

#------------------------------------------------------------------------------

#  NOTES:

#     This script modifies the Graphics module and rewrites the main 

#     method of Scene_Base.

#==============================================================================

 

#==============================================================================

# ** Pause Game Configuration Module

#==============================================================================

 

module Pause_Game

  # Scenes in which the Pause option will be enabled

  Allowed_Scenes = [Scene_Map, Scene_Battle]

  # Graphics Brightness when paused

  Graphics_Brightness = 160

  # BGM Volume when paused

  BGM_Volume = 70

  # Pause Key

  Key = Input::SHIFT

  # Pause window

  Pause_Window = true

end

 

#==============================================================================

# ** Graphics

#------------------------------------------------------------------------------

#  This module carries out graphics processing.

#==============================================================================

 

module Graphics

  class << self

    #--------------------------------------------------------------------------

    # * Alias Listing

    #--------------------------------------------------------------------------

    if @graphics_stack.nil?

      alias dargor_vx_pause_graphics_initialize initialize

      alias dargor_vx_pause_graphics_update update

      @graphics_stack = true

    end

    #--------------------------------------------------------------------------

    # * Object Initialization

    #--------------------------------------------------------------------------

    def initialize

      @paused = false

      dargor_vx_pause_graphics_initialize

    end

    #--------------------------------------------------------------------------

    # * Pause

    #--------------------------------------------------------------------------

    def pause

      return @paused

    end

    #--------------------------------------------------------------------------

    # * Pause =

    #--------------------------------------------------------------------------

    def pause=(bool)

      # Set brightness and BGM volume

      if bool

        self.brightness = Pause_Game::Graphics_Brightness

        Sound.set_bgm_volume(Pause_Game::BGM_Volume)

      else

        self.brightness = 255

        Sound.reset_bgm_volume 

      end

      # Refresh screen

      update

      # Set pause flag

      @paused = bool

    end

    #--------------------------------------------------------------------------

    # * Pause Disabled

    #--------------------------------------------------------------------------

    def pause_disabled?

      return !Pause_Game::Allowed_Scenes.include?($scene.class)

    end

    #--------------------------------------------------------------------------

    # * Frame Update

    #--------------------------------------------------------------------------

    def update

      return if @paused

      dargor_vx_pause_graphics_update

    end

  end

end

 

#==============================================================================

# ** Sound

#------------------------------------------------------------------------------

#  This module plays sound effects. It obtains sound effects specified in the

# database from $data_system, and plays them.

#==============================================================================

 

module Sound

  #--------------------------------------------------------------------------

  # * Set BGM Volume

  #--------------------------------------------------------------------------

  def self.set_bgm_volume(volume)

    RPG::BGM.last.last_volume = RPG::BGM.last.volume

    RPG::BGM.last.volume = volume

    RPG::BGM.last.play

  end

  #--------------------------------------------------------------------------

  # * Reset BGM Volume

  #--------------------------------------------------------------------------

  def self.reset_bgm_volume

    RPG::BGM.last.volume = RPG::BGM.last.last_volume

    RPG::BGM.last.play

  end

end

 

#==============================================================================

# ** RPG::AudioFile

#------------------------------------------------------------------------------

#  Superclass of BGM, BGS, ME, and SE.

#==============================================================================

 

class RPG::AudioFile

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor :last_volume

  #--------------------------------------------------------------------------

  # * Alias Listing

  #--------------------------------------------------------------------------

  alias dargor_vx_pause_audiofile_initialize initialize

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(*args)

    dargor_vx_pause_audiofile_initialize

    @last_volume = @volume

  end

end

 

#==============================================================================

# ** Scene_Base

#------------------------------------------------------------------------------

#  This is a superclass of all scenes in the game.

#==============================================================================

 

class Scene_Base

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    start                         # Start processing

    perform_transition            # Perform transition

    post_start                    # Post-start processing

    Input.update                  # Update input information

    loop do

      update_pause                # Update game pause state

      Graphics.update             # Update game screen

      Input.update                # Update input information

      next if Graphics.pause      # Cancel scene update if game is paused

      update                      # Update frame

      break if $scene != self     # When screen is switched, interrupt loop

    end

    Graphics.update

    pre_terminate                 # Pre-termination processing

    Graphics.freeze               # Prepare transition

    terminate                     # Termination processing

  end

  #--------------------------------------------------------------------------

  # * Frame Update (Pause)

  #--------------------------------------------------------------------------

  def update_pause

    # Update spriteset if it exists

    unless Graphics.pause

      terminate_pause_window

    end

    # Cancel pause update if pause is disabled

    return if Graphics.pause_disabled?

    # Update Pause effect

    if Input.trigger?(Pause_Game::Key)

      create_pause_window unless Graphics.pause

      Graphics.pause = !Graphics.pause

      return

    end

  end

  #--------------------------------------------------------------------------

  # * Create Pause Window

  #--------------------------------------------------------------------------

  def create_pause_window

    return unless @pause_window.nil?

    return unless Pause_Game::Pause_Window

    @pause_window = Window_Help.new

    @pause_window.width = 272

    @pause_window.x = Graphics.width / 2 - @pause_window.width / 2

    @pause_window.y = Graphics.height / 2 - @pause_window.height / 2

    @pause_window.create_contents

    @pause_window.set_text('Pause...',1)

  end

  #--------------------------------------------------------------------------

  # * Terminate Pause Window

  #--------------------------------------------------------------------------

  def terminate_pause_window

    return if @pause_window.nil?

    @pause_window.dispose

    @pause_window = nil

  end

end

Notes

This script rewrites the Scene_Base main method and modifies the Graphics.update method.

Enjoy!
-Dargor
 
Doesn't RMVX auto-pause whenever you're tabbed into another window? If not, this is pretty nifty (it's nifty regardless, I suppose). I'll give it a shot when I get home rom work today.
 
tofurkey":rk08lzap said:
Doesn't RMVX auto-pause whenever you're tabbed into another window?
Almost every program does that. But that's not what the script does.
It's an in-game pause feature that let you pause any scene processing.
 
Unfortunately it seems like it just lowers the volume. It would be a great feature to pause music, perfect for cutscenes that depend on BGM.
 
This is really nice if you want to have the ability to pause but have disabled the menu, like for minigames and such.

While it has next to zero REAL functionality for my game, consider it used anyway XD

Oh, and if you want to set the input key to something remappable (A,B,C,X,Y,X,L,R) just find the line:
Code:
if Input.trigger?(Pause_Game::Key)
And replace it with:
Code:
if Input.trigger?(Input::Y)
Or whatever you want to pause the game. By default that is S on your keyboard and button 5 on your gamepad.

Just tossing that out there. =)
 
Oh, and if you want to set the input key to something remappable (A,B,C,X,Y,X,L,R) just find the line:
Code:

if Input.trigger?(Pause_Game::Key)

And replace it with:
Code:

if Input.trigger?(Input::Y)

Or whatever you want to pause the game. By default that is S on your keyboard and button 5 on your gamepad.

Just tossing that out there. =)

There's already an option for changing that key :/
You just have to change the "Key" constant in the Pause_Game module. It's SHIFT by default.
 
Oh, this is just fantastic. I was actually considering requesting this, especially since I don't use much of a menu system.

Good job, Dargor, you're the man! :thumb:
 
Dargor":26vb0bt9 said:
There's already an option for changing that key :/
You just have to change the "Key" constant in the Pause_Game module. It's SHIFT by default.

There is, but you can only set it to a specific key, for example shift or Esc or whatever. My edit makes it so you can set it to the input Y key, which on the keyboard translates to whatever keys you set it to (by default S) and whatever buttons on a gamepad it's set to. From my experimenting, the way you did it is specifically the key you put in. I play with a gamepad, so I like to be able to do any function save for typing in things when applicable on that gamepad in whatever game I'm playing.
 
Thanks Vennie, I'm glad you like it! :smile:

@EmuMaster

Both SHIFT and Y belongs to the input module, so you just have to change the Key constant.
You change
Code:
Key = Input::SHIFT
for
Code:
Key = Input::Y
You don't need to change it directly in the update_pause method. It works, but it's not necessary.

@Mimi Chan, Regi
As far as I know, it's not possible to pause an AudioFile.
 

ikos

Member

Is there a way to make it to where only the "Pause..." appears, without the window around it?
Yet another cool script, Dargor. :thumb:
 
I Am Sort Of Having Troble Well See I Found A Some How To Puase BGS, ME, and SE too soi can puase all sound but i am have a problem when i unpuase it it give me errors module For
BGS, ME, and SE not found is there a way to fix that i tryed makeing a second  sound but it gave me more errors module ..... what do i do
 
@DarkImp
I'm not sure about what you're trying to say but the only thing I did to the audio part is adding a method to change the volume of a playing BGM at any time.
 

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