Help - Search - Members - Calendar
Full Version: Zoom Effect?
RPG RPG Revolution Forums > Game Engines > RPG Maker XP Discussion
SleepingSirenx
I've seen an RMXP game video demo once where when an enemy is encountered through random encounter method, the screen zooms into the player sprite then the transition commence. Is this achievable by script methods or is there some kind of event process used for it? Thanks.
Night_Runner
How does this look?

CODE
#==============================================================================
# ** XP: Night_Runner's Zoom on Battle
#----------------------------------------------------------------------------
# History:
#  Date Created: 23/Nov/2011
#  Created for SleepingSirenX
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=54039
#
# Description:
#  This script edits game_guy's Snapshot script, so when you enter a battle
#   from the map this script will take a snapshot of the map, and zoom in
#   on the player before the battle transition.
#  I've included game_guy's documentation since he created the Snapshots
#   script, which this is based on. I've removed all the code game_guy
#   made, but he collected some other scripts so I give credit for that.
#
# How to Install:
#  Copy this entire code. In your game's editor select Tools >> Script
#  Editor. Along the left hand side scroll all the way to the bottom,
#  right click on 'Main' and select 'Insert'. Paste the code on the right.
#
# Customisation:
#  You can change the zoom percent and speed on lines 33 & 34 respectively.
#==============================================================================



#==============================================================================
# ** Customisation
#==============================================================================

module NR_BattleZoom
  Percent = 10.0
  Speed = 2 * Graphics.frame_rate # How many frames it takes to zoom
  Foldername = "Snapshots/"
  Filename = "latest.png"
end



#===============================================================================
# Snapshot
# Author game_guy
# Version 1.0
#-------------------------------------------------------------------------------
# Intro:
# Ever wanted to take screenies or snapshots ingame? While there are other
# methods of doing that, this one is by far the easiest. With a simple button
# press or script call, it'll take a screenshot of the game for you and
# save it in a folder.
# Also useful for beta testing. Your testers can snapshot bugs or errors in
# mapping or stuff like that.
#
# Features:
# Take picture with button press or script call
# Customizable Button to press
#
#Instructions:
# Place screenshot.dll in your projects folder.
# Get the dll here if you need it
# http://decisive-games.com/ggp/scripts/screenshot.dll
# Make a folder in your projects folder called Snapshots
#
# To take a snapshot with a script call use this
# GameGuy.snap thats it!
#
# Compatibility:
# Not tested with SDK. (Should work though)
# Will work with anything.
#
# Credits:
# game_guy ~ For making it
# Google ~ Searching up Win32Api tutorials
# Screenshot.dll ~ Whoever made this, made this script possible
#===============================================================================

module GameGuy
  def self.snap
    snp = Win32API.new('screenshot.dll', 'Screenshot', %w(l l l l p l l), '')
    window = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
    ini = (Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p),
    'l')
    game_name = "\0" * 256
    ini.call('Game', 'Title', '', game_name, 255, '.\Game.ini')
    game_name.delete!('\0')
    win = window.call('RGSS Player', game_name)
    dir = Dir.new((NR_BattleZoom::Foldername).gsub(/\//, ""))
    count = 0
    dir.entries.each {|i| count += 1}
    file_name = NR_BattleZoom::Foldername + NR_BattleZoom::Filename
    snp.call(0, 0, 640, 480, file_name, win, 2)
  end
end



#==============================================================================
# ** RPG::Cache
#----------------------------------------------------------------------------
#  Edited to load the snapshot.
#==============================================================================

module RPG::Cache
  #--------------------------------------------------------------------------
  # * Snapshot
  #--------------------------------------------------------------------------
  def self.snapshot(filename)
    self.load_bitmap(NR_BattleZoom::Foldername, filename)
  end
end



#==============================================================================
# ** Scene_Map
#----------------------------------------------------------------------------
#  Edited to zoom in on the map when battle starts.
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias nr_battleZoom_call_battle  call_battle  unless $@
  #--------------------------------------------------------------------------
  # * Center to player at zoom
  #--------------------------------------------------------------------------
  def center(zoom)
    max_x = ($game_map.width - 20 / zoom) * 32 * zoom
    max_y = ($game_map.height - 15 / zoom) * 32 * zoom
    x = [0, [$game_player.screen_x * zoom - 320, max_x].min].max
    y = [0, [$game_player.screen_y * zoom - 240 - 28 * zoom, max_y].min].max
    return x, y
  end
  #--------------------------------------------------------------------------
  # * Call Battle
  #--------------------------------------------------------------------------
  def call_battle(*args)
    # Take the screenshot
    GameGuy.snap
    # Run the original call_battle
    nr_battleZoom_call_battle(*args)
    # Load the screenshot
    @map_zoom_sprite = Sprite.new()
    @map_zoom_sprite.z = 5001
    @map_zoom_sprite.bitmap = RPG::Cache.snapshot(NR_BattleZoom::Filename)
    speed = NR_BattleZoom::Speed
    # Get the rate of change of zoom
    zoom_grad = ((NR_BattleZoom::Percent).to_f - 1.0) /NR_BattleZoom::Speed.to_f
    # Loop through zoom
    for i in 1..speed
      # Get the zoom for this loop
      zoom = zoom_grad * i.to_f + 1.0
      # Get the x & y to show the map at for the zoom
      x, y = center(zoom)
      # Apploy the zoom and move the picture to zoom in on the player
      @map_zoom_sprite.zoom_x = @map_zoom_sprite.zoom_y = zoom
      @map_zoom_sprite.x = -x
      @map_zoom_sprite.y = -y
      # Update the graphics
      Graphics.update
    end
    # Greeze the graphics zoomed in
    Graphics.freeze
    # Dispose the zoomed in graphics
    @map_zoom_sprite.bitmap.dispose
    @map_zoom_sprite.dispose
  end
end



#==============================================================================
# ** End of Script.
#==============================================================================


The only thing is you need to have the screenshot.dll (link) in the root directory of your game (so extract the zip file to the same folder as the Game.rxproj, etc).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.