• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
  • Eevee Expo's webhost has been having technical issues since Nov. 20th and you might be unable to connect to our site. Staff are also facing issues connecting, so please send a DM to Cat on-site or through Discord directly for faster service!
Map Zoom

v20.1 Map Zoom 2022-05-19

This resource pertains to version 20.1 of Pokémon Essentials.
Pokémon Essentials Version
v20.1 ➖
bikezoom.gif
battlezoom.gif


Simple script to get a little fancy with the camera!

Code
The plugin can be downloaded here (v20), or you can just paste this code in a new script section above Main:
Ruby:
Expand Collapse Copy
class ZoomMap
  attr_accessor :goal
  attr_accessor :speed
  attr_accessor :zoom

  def initialize(goal,speed,zoom="in")
    @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
    @viewport.z = 99999
    self.goal = goal
    self.speed = speed
    self.zoom = zoom.downcase
    @sprites = {}
    @sprites["map"] = Sprite.new(@viewport)
    @sprites["map"].bitmap =  Graphics.snap_to_bitmap
    @sprites["map"].center_origins
    @sprites["map"].x = Graphics.width/2
    @sprites["map"].y = Graphics.height/2
    Graphics.update
  end
 
 
  def update
    if @sprites
      @sprites["map"].bitmap.clear
      messagewindow = $game_temp.message_window
      cmdwindow = $game_temp.cmd_window
      pausemenu = $game_temp.pause_menu_scene
      messagewindow.visible = false if messagewindow
      cmdwindow.visible = false if cmdwindow
      pausemenu.pbHideMenu if pausemenu
      @sprites["map"].bitmap =  Graphics.snap_to_bitmap
      @sprites["map"].center_origins
      @sprites["map"].x = Graphics.width/2
      @sprites["map"].y = Graphics.height/2
      messagewindow.visible = true if messagewindow
      cmdwindow.visible = true if cmdwindow
      pausemenu.pbShowMenu if pausemenu
      case self.zoom
        when "in"
          if @sprites["map"].zoom < self.goal
            altspeed = self.goal - @sprites["map"].zoom
            @sprites["map"].zoom+=[self.speed,altspeed].min
          end
        when "out"
          if @sprites["map"].zoom > @goal
            altspeed = @sprites["map"].zoom - self.goal
            @sprites["map"].zoom-=[self.speed,altspeed].min
          end
        end
    else
      dispose
    end
  end
 
 
  def dispose
    pbDisposeSpriteHash(@sprites)
    @viewport.dispose
  end
 
end


def pbZoomMap(goal,speed,zoom="in")
  if !$game_temp.background_zoom
    $game_temp.background_zoom = ZoomMap.new(goal,speed,zoom)
  else
    $game_temp.background_zoom.goal = goal
    $game_temp.background_zoom.speed = speed
    $game_temp.background_zoom.zoom = zoom
  end
end


def pbDisposeZoomMap
  if $game_temp.background_zoom
    $game_temp.background_zoom.dispose
    $game_temp.background_zoom = nil
  end
      Graphics.update
end


EventHandlers.add(:on_frame_update,:map_zoom,
  proc {
  next if !$player
  if $game_temp.background_zoom.is_a?(ZoomMap)
  $game_temp.background_zoom.update
  sprites = $game_temp.background_zoom.instance_variable_get(:@sprites)
    if $game_temp.background_zoom.goal == 1 && sprites["map"].zoom == 1
      pbDisposeZoomMap
    end
  end
  }
)


#===============================================================================
#Pause Menu Rewriting
#===============================================================================
#If you're using an alternate pause UI,
#you should probably delete this whole section.


class Scene_Map
 
  def call_menu
    $game_temp.menu_calling = false
    $game_temp.in_menu = true
    $game_player.straighten
    $game_map.update
    $game_temp.pause_menu_scene = PokemonPauseMenu_Scene.new
    $game_temp.pause_menu_screen = PokemonPauseMenu.new($game_temp.pause_menu_scene)
    $game_temp.pause_menu_screen.pbStartPokemonMenu
    $game_temp.in_menu = false
  end
 
end


class PokemonPauseMenu_Scene
  def pbShowMenu
    @sprites["cmdwindow"].visible = true if @sprites["cmdwindow"]
    @sprites["infowindow"].visible = @infostate if @sprites["infowindow"]
    @sprites["helpwindow"].visible = @helpstate if @sprites["helpwindow"]
  end

  def pbHideMenu
    @sprites["cmdwindow"].visible = false if @sprites["cmdwindow"]
    @sprites["infowindow"].visible = false if @sprites["infowindow"]
    @sprites["helpwindow"].visible = false if @sprites["helpwindow"]
  end
end

#===============================================================================
#Sprite Utilities
#===============================================================================
#If you have these utilities defined elsewhere, you can delete this section.
class Sprite
  #Utility from Marin
  # Centers the sprite by setting the origin points to half the width and height
  def center_origins
    return if !self.bitmap
    self.ox = self.bitmap.width / 2
    self.oy = self.bitmap.height / 2
  end
 
  #Utility from Luka
  #-----------------------------------------------------------------------------
  #  gets zoom
  #-----------------------------------------------------------------------------
  def zoom
    return self.zoom_x
  end
  #-----------------------------------------------------------------------------
  #  sets all zoom values
  #-----------------------------------------------------------------------------
  def zoom=(val)
    self.zoom_x = val
    self.zoom_y = val
  end
 
end



#===============================================================================
#Game Temp and Message Window rewriting
#===============================================================================
#This code is to allow the ZoomMap class to hide these windows
#when taking a screenshot, so that the text won't be zoomed in.
class Game_Temp
  attr_accessor :background_zoom
  attr_accessor :message_window
  attr_accessor :cmd_window
  attr_accessor :pause_menu_scene
  attr_accessor :pause_menu_screen
 
end



def pbCreateMessageWindow(viewport=nil,skin=nil)
  $game_temp.message_window = Window_AdvancedTextPokemon.new("")
  msgwindow=$game_temp.message_window
  if !viewport
    msgwindow.z=99999
  else
    msgwindow.viewport=viewport
  end
  msgwindow.visible=true
  msgwindow.letterbyletter=true
  msgwindow.back_opacity=MessageConfig::WINDOW_OPACITY
  pbBottomLeftLines(msgwindow,2)
  $game_temp.message_window_showing=true if $game_temp
  skin=MessageConfig.pbGetSpeechFrame() if !skin
  msgwindow.setSkin(skin)
  return msgwindow
end

def pbDisposeMessageWindow(msgwindow)
  $game_temp.message_window_showing=false if $game_temp
  $game_temp.message_window.dispose if $game_temp.message_window
  msgwindow.dispose
end



def pbShowCommands(msgwindow,commands=nil,cmdIfCancel=0,defaultCmd=0)
  return 0 if !commands
  $game_temp.cmd_window = Window_CommandPokemonEx.new(commands)
  cmdwindow = $game_temp.cmd_window
  cmdwindow.z=99999
  cmdwindow.visible=true
  cmdwindow.resizeToFit(cmdwindow.commands)
  pbPositionNearMsgWindow(cmdwindow,msgwindow,:right)
  cmdwindow.index=defaultCmd
  command=0
  loop do
    Graphics.update
    Input.update
    cmdwindow.update
    msgwindow.update if msgwindow
    yield if block_given?
    if Input.trigger?(Input::BACK)
      if cmdIfCancel>0
        command=cmdIfCancel-1
        break
      elsif cmdIfCancel<0
        command=cmdIfCancel
        break
      end
    end
    if Input.trigger?(Input::USE)
      command=cmdwindow.index
      break
    end
    pbUpdateSceneMap
  end
  ret=command
  cmdwindow.dispose
  Input.update
  return ret
end

def pbShowCommandsWithHelp(msgwindow,commands,help,cmdIfCancel=0,defaultCmd=0)
  msgwin=msgwindow
  msgwin=pbCreateMessageWindow(nil) if !msgwindow
  oldlbl=msgwin.letterbyletter
  msgwin.letterbyletter=false
  if commands
    $game_temp.cmd_window = Window_CommandPokemonEx.new(commands)
    cmdwindow = $game_temp.cmd_window
    cmdwindow.z=99999
    cmdwindow.visible=true
    cmdwindow.resizeToFit(cmdwindow.commands)
    cmdwindow.height=msgwin.y if cmdwindow.height>msgwin.y
    cmdwindow.index=defaultCmd
    command=0
    msgwin.text=help[cmdwindow.index]
    msgwin.width=msgwin.width   # Necessary evil to make it use the proper margins
    loop do
      Graphics.update
      Input.update
      oldindex=cmdwindow.index
      cmdwindow.update
      if oldindex!=cmdwindow.index
        msgwin.text=help[cmdwindow.index]
      end
      msgwin.update
      yield if block_given?
      if Input.trigger?(Input::BACK)
        if cmdIfCancel>0
          command=cmdIfCancel-1
          break
        elsif cmdIfCancel<0
          command=cmdIfCancel
          break
        end
      end
      if Input.trigger?(Input::USE)
        command=cmdwindow.index
        break
      end
      pbUpdateSceneMap
    end
    ret=command
    cmdwindow.dispose
    Input.update
  end
  msgwin.letterbyletter=oldlbl
  msgwin.dispose if !msgwindow
  return ret
end
Ruby:
Expand Collapse Copy
class ZoomMap
  attr_accessor :goal
  attr_accessor :speed
  attr_accessor :zoom

  def initialize(goal,speed,zoom="in")
    @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
    @viewport.z = 99999
    self.goal = goal
    self.speed = speed
    self.zoom = zoom.downcase
    @sprites = {}
    @sprites["map"] = Sprite.new(@viewport)
    @sprites["map"].bitmap =  Graphics.snap_to_bitmap
    @sprites["map"].center_origins
    @sprites["map"].x = Graphics.width/2
    @sprites["map"].y = Graphics.height/2
    Graphics.update
  end
 
 
  def update
    if @sprites
      @sprites["map"].bitmap.clear
      messagewindow = $game_temp.message_window
      cmdwindow = $game_temp.cmd_window
      pausemenu = $game_temp.pause_menu_scene
      messagewindow.visible = false if messagewindow
      cmdwindow.visible = false if cmdwindow
      pausemenu.pbHideMenu if pausemenu
      @sprites["map"].bitmap =  Graphics.snap_to_bitmap
      @sprites["map"].center_origins
      @sprites["map"].x = Graphics.width/2
      @sprites["map"].y = Graphics.height/2
      messagewindow.visible = true if messagewindow
      cmdwindow.visible = true if cmdwindow
      pausemenu.pbShowMenu if pausemenu
      case self.zoom
        when "in"
          if @sprites["map"].zoom < self.goal
            altspeed = self.goal - @sprites["map"].zoom
            @sprites["map"].zoom+=[self.speed,altspeed].min
          end
        when "out"
          if @sprites["map"].zoom > @goal
            altspeed = @sprites["map"].zoom - self.goal
            @sprites["map"].zoom-=[self.speed,altspeed].min
          end
        end
    else
      dispose
    end
  end
 
 
  def dispose
    pbDisposeSpriteHash(@sprites)
    @viewport.dispose
  end
 
end


def pbZoomMap(goal,speed,zoom="in")
  if !$game_temp.background_zoom
    $game_temp.background_zoom = ZoomMap.new(goal,speed,zoom)
  else
    $game_temp.background_zoom.goal = goal
    $game_temp.background_zoom.speed = speed
    $game_temp.background_zoom.zoom = zoom
  end
end


def pbDisposeZoomMap
  if $game_temp.background_zoom
    $game_temp.background_zoom.dispose
    $game_temp.background_zoom = nil
  end
      Graphics.update
end

Events.onMapUpdate += proc { |_sender,_e|
  next if !$Trainer
  if $game_temp.background_zoom.is_a?(ZoomMap)
  $game_temp.background_zoom.update
  sprites = $game_temp.background_zoom.instance_variable_get(:@sprites)
    if $game_temp.background_zoom.goal == 1 && sprites["map"].zoom == 1
      pbDisposeZoomMap
    end
  end
}


#===============================================================================
#Pause Menu Rewriting
#===============================================================================
#If you're using an alternate pause UI,
#you should probably delete this whole section.


class Scene_Map
 
  def call_menu
    $game_temp.menu_calling = false
    $game_temp.in_menu = true
    $game_player.straighten
    $game_map.update
    $game_temp.pause_menu_scene = PokemonPauseMenu_Scene.new
    $game_temp.pause_menu_screen = PokemonPauseMenu.new($game_temp.pause_menu_scene)
    $game_temp.pause_menu_screen.pbStartPokemonMenu
    $game_temp.in_menu = false
  end
 
end


class PokemonPauseMenu_Scene
  def pbShowMenu
    @sprites["cmdwindow"].visible = true if @sprites["cmdwindow"]
    @sprites["infowindow"].visible = @infostate if @sprites["infowindow"]
    @sprites["helpwindow"].visible = @helpstate if @sprites["helpwindow"]
  end

  def pbHideMenu
    @sprites["cmdwindow"].visible = false if @sprites["cmdwindow"]
    @sprites["infowindow"].visible = false if @sprites["infowindow"]
    @sprites["helpwindow"].visible = false if @sprites["helpwindow"]
  end
end

#===============================================================================
#Sprite Utilities
#===============================================================================
#If you have these utilities defined elsewhere, you can delete this section.
class Sprite
  #Utility from Marin
  # Centers the sprite by setting the origin points to half the width and height
  def center_origins
    return if !self.bitmap
    self.ox = self.bitmap.width / 2
    self.oy = self.bitmap.height / 2
  end
 
  #Utility from Luka
  #-----------------------------------------------------------------------------
  #  gets zoom
  #-----------------------------------------------------------------------------
  def zoom
    return self.zoom_x
  end
  #-----------------------------------------------------------------------------
  #  sets all zoom values
  #-----------------------------------------------------------------------------
  def zoom=(val)
    self.zoom_x = val
    self.zoom_y = val
  end
 
end



#===============================================================================
#Game Temp and Message Window rewriting
#===============================================================================
#This code is to allow the ZoomMap class to hide these windows
#when taking a screenshot, so that the text won't be zoomed in.
class Game_Temp
  attr_accessor :background_zoom
  attr_accessor :message_window
  attr_accessor :cmd_window
  attr_accessor :pause_menu_scene
  attr_accessor :pause_menu_screen
 
end



def pbCreateMessageWindow(viewport=nil,skin=nil)
  $game_temp.message_window = Window_AdvancedTextPokemon.new("")
  msgwindow=$game_temp.message_window
  if !viewport
    msgwindow.z=99999
  else
    msgwindow.viewport=viewport
  end
  msgwindow.visible=true
  msgwindow.letterbyletter=true
  msgwindow.back_opacity=MessageConfig::WINDOW_OPACITY
  pbBottomLeftLines(msgwindow,2)
  $game_temp.message_window_showing=true if $game_temp
  skin=MessageConfig.pbGetSpeechFrame() if !skin
  msgwindow.setSkin(skin)
  return msgwindow
end

def pbDisposeMessageWindow(msgwindow)
  $game_temp.message_window_showing=false if $game_temp
  $game_temp.message_window.dispose if $game_temp.message_window
  msgwindow.dispose
end



def pbShowCommands(msgwindow,commands=nil,cmdIfCancel=0,defaultCmd=0)
  return 0 if !commands
  $game_temp.cmd_window = Window_CommandPokemonEx.new(commands)
  cmdwindow = $game_temp.cmd_window
  cmdwindow.z=99999
  cmdwindow.visible=true
  cmdwindow.resizeToFit(cmdwindow.commands)
  pbPositionNearMsgWindow(cmdwindow,msgwindow,:right)
  cmdwindow.index=defaultCmd
  command=0
  loop do
    Graphics.update
    Input.update
    cmdwindow.update
    msgwindow.update if msgwindow
    yield if block_given?
    if Input.trigger?(Input::BACK)
      if cmdIfCancel>0
        command=cmdIfCancel-1
        break
      elsif cmdIfCancel<0
        command=cmdIfCancel
        break
      end
    end
    if Input.trigger?(Input::USE)
      command=cmdwindow.index
      break
    end
    pbUpdateSceneMap
  end
  ret=command
  cmdwindow.dispose
  Input.update
  return ret
end

def pbShowCommandsWithHelp(msgwindow,commands,help,cmdIfCancel=0,defaultCmd=0)
  msgwin=msgwindow
  msgwin=pbCreateMessageWindow(nil) if !msgwindow
  oldlbl=msgwin.letterbyletter
  msgwin.letterbyletter=false
  if commands
    $game_temp.cmd_window = Window_CommandPokemonEx.new(commands)
    cmdwindow = $game_temp.cmd_window
    cmdwindow.z=99999
    cmdwindow.visible=true
    cmdwindow.resizeToFit(cmdwindow.commands)
    cmdwindow.height=msgwin.y if cmdwindow.height>msgwin.y
    cmdwindow.index=defaultCmd
    command=0
    msgwin.text=help[cmdwindow.index]
    msgwin.width=msgwin.width   # Necessary evil to make it use the proper margins
    loop do
      Graphics.update
      Input.update
      oldindex=cmdwindow.index
      cmdwindow.update
      if oldindex!=cmdwindow.index
        msgwin.text=help[cmdwindow.index]
      end
      msgwin.update
      yield if block_given?
      if Input.trigger?(Input::BACK)
        if cmdIfCancel>0
          command=cmdIfCancel-1
          break
        elsif cmdIfCancel<0
          command=cmdIfCancel
          break
        end
      end
      if Input.trigger?(Input::USE)
        command=cmdwindow.index
        break
      end
      pbUpdateSceneMap
    end
    ret=command
    cmdwindow.dispose
    Input.update
  end
  msgwin.letterbyletter=oldlbl
  msgwin.dispose if !msgwindow
  return ret
end

Using this Script

You've just got the two calls here!

pbZoomMap(goal,speed,zoom="in")


Goal is the zoom level that you want to reach. Remember that a normal zoom is 1- think of it as "1 = 100%". A goal of 2 would have your map zoom in to 200%.

Speed is the amount that the zoom increases/decreases by per frame. If you're doing an amount less than 1, remember to put a 0 before the decimal- 0.5 instead of .5, for example.

Set zoom to "out" to zoom out. (speed should still be a positive number)

pbDisposeZoomMap gets rid of the zoom. Note that it does so abruptly, without zooming out- it's mostly just there for cases like exiting a map, where the fade to black will keep it from being too jarring. If you to remove it while the player's still on the map, you should zoom back out to 1 through pbZoomMap.

Please note that this is only for zooming in from standard view and zooming back out from a zoomed-in view- it currently cannot zoom out any further, and I don't think that's actually possible to do. (I'll look into it later, though.)

If you're using a pause menu with its own GUI- for example, bop's HGSS menu- you should delete the section that starts with "Pause Menu Rewriting" to avoid conflicts between the two.

Because the zoom is stored in $game_temp, it's deleted when the player closes the game. If you want a map to be zoomed when the player has control, you should probably have a parallel process or autoplay event, so that players who save on the map can reload their game without breaking the zoom.
Future Goals
  • I... may need to fix the save window as well, I'll get that soon.
  • I'm pretty sure zooming out is impossible, but I'll write it here in case I ever get around to the possibility.
Credits
Marin and Luka SJ for their script utilities
Golisopod User for the textbox fix
TechSkylander1518 for the rest of the code
Author
TechSkylander1518
Downloads
802
Views
5,281
First release
Last update

Ratings

5.00 star(s) 6 ratings

More resources from TechSkylander1518

Latest updates

  1. v20 Update

    Quick update for v20! Luckily, most of this was still compatible, so there were very few...
  2. Windows fixed!

    Thanks to some help from Golisopod User, the windows have been fixed! Show text, show command...

Latest reviews

Fantastic. It's been a game changer to my project.
Works perfect! Great job! It will be cool to try it out.
This script works perfectly! Also simple and easy to use!
Absolutely amazing! I have a meme character in my game, and this script zooms in to him each time he's animated! Great job, Tech!
TechSkylander1518
TechSkylander1518
Thank you!! Sounds like you're really putting it to some use, haha!
Back
Top