Zelda-Style Map ScrollVersion: 1.0
By: Glaciesflamma
Introduction
This is something I'm sure has been asked for before, but I hadn't seen anyone produce the script just yet - at least not quite in the way I had hoped for when I started looking around. So I set to work to make it myself.
This Script was possible only thanks to SephirothSpawn's Tilemap Class Rewrite. I Used his script as a base and edited it as needed
This script creates 2D Zelda-Style Map Transitioning. As the Game Player approaches the maps edge, and tries to move off it, the script will load and draw the adjacent map, pan the screen over, and then load the adjacent map completely once done. The only condition of these is that the adjacent edges of the map must be equal in size, and 'lined up' (i.e. if moving left/right, the x coordinates are parallel to each other.)
This is accomplished mostly through the script itself, though the Game Maker will have to make a single event on each map titled "Transfer" that indicates the map ids of the map located in each direction. Leaving a direction out will prevent the transition for attempting to happen.
Features
Screenshots
Currently, I do not have any screenshots [I feel this would be hard to demonstrate via screenshots anyhow]. However, feel free to check out the script at work in the demo!
Demo
Zelda Map Scroll Demo
Script
Instructions
1) Create a new Script just above main and paste the Tilemap Script
2) Create a new Script above main but below the Tilemap Script and paste the Zelda Scroll Script
3) On any map you'd like to use it on, create an Event an call it "Transfer". I usually like to put it in the upper left corner, but that isn't required.
4) In the Event, create a comment of "<direction>:<map id>" for each edge you would like to connect to the map.
In this case, <direction> is the direction the $game_player would be heading as he left the current map [Left, Right, Up, Down]
<map id> is the ID of the map you want to connect to.
Make sure there are no spaces.
5) Enjoy!
FAQ
I will add to this as questions arise
Compatibility
This script is NOT SDK compatible.
That said, it edits a large number of methods and classes, so I'm sure there will be some compatibility issues.
As a note, it completely rewrites the Sprite_Character class. In also rewrites the update method for Game_Map, Game_Player, and Scene_Map completely.
Credits and Thanks
SephirothSpawn for his Tilemap Class
Author's Notes
This is a rough, general version without alot of thrills or extras. That said, it works pretty well.
If you have any questions or comments, I'd love to hear them. However, I don't stop by this board that often, so I would recommend PMing me or emailing me if you have any pressing concerns. Otherwise, I will reply whenever I happen by.
Terms and Conditions
Feel free to use the scripts however you like, so long as credit is given to SephirothSpawn for the Tilemap Class and myself for the rest. However, please do not post this anywhere else without my permission. Thanks!
By: Glaciesflamma
Introduction
This is something I'm sure has been asked for before, but I hadn't seen anyone produce the script just yet - at least not quite in the way I had hoped for when I started looking around. So I set to work to make it myself.
This Script was possible only thanks to SephirothSpawn's Tilemap Class Rewrite. I Used his script as a base and edited it as needed
This script creates 2D Zelda-Style Map Transitioning. As the Game Player approaches the maps edge, and tries to move off it, the script will load and draw the adjacent map, pan the screen over, and then load the adjacent map completely once done. The only condition of these is that the adjacent edges of the map must be equal in size, and 'lined up' (i.e. if moving left/right, the x coordinates are parallel to each other.)
This is accomplished mostly through the script itself, though the Game Maker will have to make a single event on each map titled "Transfer" that indicates the map ids of the map located in each direction. Leaving a direction out will prevent the transition for attempting to happen.
Features
- Zelda-Style Map scrolling from one map to another
- Able to transition to maps with different tilesets
- Will draw and support events located on new map as transition occurs
Screenshots
Currently, I do not have any screenshots [I feel this would be hard to demonstrate via screenshots anyhow]. However, feel free to check out the script at work in the demo!
Demo
Zelda Map Scroll Demo
Script
Tilemap Script
Show
- #==============================================================================
- # Tilemap Class
- #------------------------------------------------------------------------------
- # Script by SephirothSpawn
- #==============================================================================
- class Tilemap
- #--------------------------------------------------------------------------
- Animated_Autotiles_Frames = 15
- #--------------------------------------------------------------------------
- Autotiles = [
- [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27, 6, 33, 34], [ 5, 6, 33, 34],
- [27, 28, 33, 12], [ 5, 28, 33, 12], [27, 6, 33, 12], [ 5, 6, 33, 12] ],
- [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27, 6, 11, 34], [ 5, 6, 11, 34],
- [27, 28, 11, 12], [ 5, 28, 11, 12], [27, 6, 11, 12], [ 5, 6, 11, 12] ],
- [ [25, 26, 31, 32], [25, 6, 31, 32], [25, 26, 31, 12], [25, 6, 31, 12],
- [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
- [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
- [39, 40, 45, 46], [ 5, 40, 45, 46], [39, 6, 45, 46], [ 5, 6, 45, 46] ],
- [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
- [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
- [ [37, 38, 43, 44], [37, 6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
- [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1, 2, 7, 8] ]
- ]
- #--------------------------------------------------------------------------
- attr_reader :layers
- attr_accessor :tileset
- attr_accessor :autotiles
- attr_accessor :map_data
- attr_accessor :flash_data
- attr_accessor :priorities
- attr_accessor :visible
- attr_accessor :ox
- attr_accessor :oy
- #--------------------------------------------------------------------------
- def initialize(viewport, map = $game_map.map)
- @layers = []
- for l in 0...6
- layer = (true ? Plane.new(viewport) : Sprite.new(viewport))
- layer.bitmap = Bitmap.new(map.width * 32, map.height * 32)
- layer.z = l * 160
- @layers << layer
- end
- @tileset = nil # Refers to Map Tileset Name
- @autotiles = [] # Refers to Tileset Auto-Tiles (Actual Auto-Tiles)
- @map_data = nil # Refers to 3D Array Of Tile Settings
- @flash_data = nil # Refers to 3D Array of Tile Flashdata
- @priorities = nil # Refers to Tileset Priorities
- @visible = true # Refers to Tilest Visibleness
- @ox = 0 # Bitmap Offsets
- @oy = 0 # bitmap Offsets
- @data = nil # Acts As Refresh Flag
- @map = map
- @tone = Tone.new(0,0,0,0)
- @plane = true
- @zoom_x = 1.0
- @zoom_y = 1.0
- @tile_width = 32
- @tile_height = 32
- end
- #--------------------------------------------------------------------------
- def prepare_transition(new_map, dir, viewport)
- @new_map = new_map
- @new_data = @new_map.data
- @dir = dir
- for l in 0...6
- @layers[l].dispose
- @layers[l] = nil
- layer = (true ? Plane.new(viewport) : Sprite.new(viewport))
- layer.bitmap = Bitmap.new((@map.width + @new_map.width) * 32,
- (@map.height + @new_map.height) * 32)
- layer.z = l * 160
- @layers[l] = layer
- end
- if @dir == 4
- @ox = @new_data.xsize * 53
- elsif @dir == 8
- @oy = @new_data.ysize * 128
- end
- merge_refresh
- end
- #--------------------------------------------------------------------------
- def dispose
- for layer in @layers
- layer.dispose
- end
- end
- #--------------------------------------------------------------------------
- def update
- if @data != @map_data or (@new_map != nil and @new_data != @new_data)
- if @new_map == nil
- refresh
- else
- merge_refresh
- end
- end
- unless @tone == $game_screen.tone
- @tone = $game_screen.tone
- @tone = Tone.new(0, 0, 0, 0) if @tone.nil?
- for layer in @layers
- layer.tone = @tone
- layer.tone = @tone
- end
- end
- for layer in @layers
- layer.ox = @ox
- layer.oy = @oy
- layer.z = @layers.index(layer) * 32
- end
- if Graphics.frame_count % Animated_Autotiles_Frames == 0
- refresh_autotiles
- end
- end
- #--------------------------------------------------------------------------
- def refresh
- @data = @map_data
- for p in 0..5
- for z in 0...@map_data.zsize
- for x in 0...@map_data.xsize
- for y in 0...@map_data.ysize
- id = @map_data[x, y, z]
- next if id == 0
- next unless p == @priorities[id]
- id < 384 ? draw_autotile(x, y, p, id) : draw_tile(x, y, p, id)
- end
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- def merge_refresh
- @data = @map_data
- @new_data = @new_map.data
- z_max = @map_data.zsize
- if [2,8].include?(@dir)
- x_max = @map_data.xsize
- y_max = @map_data.ysize + @new_data.ysize
- elsif [4,6].include?(@dir)
- x_max = @map_data.xsize + @new_data.xsize
- y_max = @map_data.ysize
- end
- for p in 0..5
- for z in 0...z_max
- for x in 0...x_max
- for y in 0...y_max
- if [2,8].include?(@dir)
- if y < @map_data.ysize
- id = @map_data[x, y, z]
- draw_map = @map
- else
- id = @new_data[x, y - @map_data.ysize, z]
- draw_map = @new_map
- end
- elsif [4,6].include?(@dir)
- if x < @map_data.xsize
- id = @map_data[x, y, z]
- draw_map = @map
- else
- id = @new_data[x - @map_data.xsize, y, z]
- draw_map = @new_map
- end
- end
- next if id == 0
- next unless p == $data_tilesets[draw_map.tileset_id].priorities[id]
- id < 384 ? draw_autotile(x, y, p, id, draw_map) : draw_tile(x, y, p, id, draw_map)
- end
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- def refresh_autotiles
- autotile_locations = Table.new(@map_data.xsize, @map_data.ysize,
- @map_data.zsize)
- for p in 0..5
- for z in 0...@map_data.zsize
- for x in 0...@map_data.xsize
- for y in 0...@map_data.ysize
- id = @map_data[x, y, z]
- next if id == 0
- next unless p == @priorities[id]
- if id < 384
- next unless @autotiles[id / 48 - 1].width / 96 > 1
- draw_autotile(x, y, p, id)
- autotile_locations[x, y, 0] = 1
- autotile_locations[x, y, 1] = 1
- autotile_locations[x, y, 2] = 1
- else
- if autotile_locations[x, y, z] == 1
- draw_tile(x, y, p, id)
- end
- end
- end
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- def draw_tile(x, y, z, id, source=@map)
- tileset = RPG::Cache.tileset($data_tilesets[source.tileset_id].tileset_name)
- rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
- x *= @tile_width
- y *= @tile_height
- if @tile_width == 32 && @tile_height == 32
- @layers[z].bitmap.blt(x, y, tileset, rect)
- else
- dest_rect = Rect.new(x, y, @tile_width, @tile_height)
- @layers[z].bitmap.stretch_blt(dest_rect, tileset, rect)
- end
- end
- #--------------------------------------------------------------------------
- def draw_autotile(x, y, z, tile_id, source = @map)
- if source == @map
- autotile = @autotiles[tile_id / 48 - 1]
- else
- autotile = RPG::Cache.autotile(@new_map.autotile_names[tile_id / 48 - 1])
- end
- tile_id %= 48
- bitmap = Bitmap.new(32, 32)
- tiles = Autotiles[tile_id / 8][tile_id % 8]
- frames = autotile.width / 96
- anim = (Graphics.frame_count / Animated_Autotiles_Frames) % frames * 96
- for i in 0...4
- tile_position = tiles[i] - 1
- src_rect = Rect.new(tile_position % 6 * 16 + anim,
- tile_position / 6 * 16, 16, 16)
- bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
- end
- x *= @tile_width
- y *= @tile_height
- if @tile_width == 32 && @tile_height == 32
- @layers[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32))
- else
- dest_rect = Rect.new(x, y, @tile_width, @tile_height)
- @layers[z].bitmap.stretch_blt(dest_rect, bitmap, Rect.new(0, 0, 32, 32))
- end
- end
- #--------------------------------------------------------------------------
- def bitmap
- bitmap = Bitmap.new(@layers[0].bitmap.width, @layers[0].bitmap.height)
- for layer in @layers
- bitmap.blt(0, 0, layer.bitmap, Rect.new(0, 0,
- bitmap.width, bitmap.height))
- end
- return bitmap
- end
- #--------------------------------------------------------------------------
- end
Expand to see the code.
Zelda Scroll Script
Show
- class Game_Temp
- attr_accessor :map_transitioning
- alias original_initialize initialize
- def initialize
- original_initialize
- @map_transitioning = false
- end
- end
- class Game_Map
- attr_reader :map_link
- #--------------------------------------------------------------------------
- # * Setup
- # map_id : map ID
- #--------------------------------------------------------------------------
- def setup(map_id)
- # Put map ID in @map_id memory
- @map_id = map_id
- # Load map from file and set @map
- @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
- # set tile set information in opening instance variables
- tileset = $data_tilesets[@map.tileset_id]
- @tileset_name = tileset.tileset_name
- @autotile_names = tileset.autotile_names
- @panorama_name = tileset.panorama_name
- @panorama_hue = tileset.panorama_hue
- @fog_name = tileset.fog_name
- @fog_hue = tileset.fog_hue
- @fog_opacity = tileset.fog_opacity
- @fog_blend_type = tileset.fog_blend_type
- @fog_zoom = tileset.fog_zoom
- @fog_sx = tileset.fog_sx
- @fog_sy = tileset.fog_sy
- @battleback_name = tileset.battleback_name
- @passages = tileset.passages
- @priorities = tileset.priorities
- @terrain_tags = tileset.terrain_tags
- # Initialize displayed coordinates
- @display_x = 0
- @display_y = 0
- # Clear refresh request flag
- @need_refresh = false
- # Set map event data
- @events = {}
- @map_link = [nil,0,0,0,0]
- for i in @map.events.keys
- @events[i] = Game_Event.new(@map_id, @map.events[i])
- if @map.events[i].name == "Transfer"
- for command in @map.events[i].pages[0].list
- if command.parameters[0].is_a?(String)
- if command.parameters[0]upcase..include?("LEFT")
- left = command.parameters[0].split(':')[1]
- elsif command.parameters[0].upcase.include?("UP")
- up = command.parameters[0].split(':')[1]
- elsif command.parameters[0].upcase.include?("RIGHT")
- right = command.parameters[0].split(':')[1]
- elsif command.parameters[0].upcase.include?("DOWN")
- down = command.parameters[0].split(':')[1]
- end
- else
- break
- end
- end
- @map_link[1] = down.to_i
- @map_link[2] = left.to_i
- @map_link[3] = right.to_i
- @map_link[4] = up.to_i
- end
- end
- # Set common event data
- @common_events = {}
- for i in 1...$data_common_events.size
- @common_events[i] = Game_CommonEvent.new(i)
- end
- # Initialize all fog information
- @fog_ox = 0
- @fog_oy = 0
- @fog_tone = Tone.new(0, 0, 0, 0)
- @fog_tone_target = Tone.new(0, 0, 0, 0)
- @fog_tone_duration = 0
- @fog_opacity_duration = 0
- @fog_opacity_target = 0
- # Initialize scroll information
- @scroll_direction = 2
- @scroll_rest = 0
- @scroll_speed = 4
- @transition_direction = 2
- @transition_rest = 0
- @transition_speed = 4
- end
- #--------------------------------------------------------------------------
- # * Get Map
- #--------------------------------------------------------------------------
- def map
- return @map
- end
- #--------------------------------------------------------------------------
- # * Get Map
- #--------------------------------------------------------------------------
- def tileset_id
- return @map.tileset_id
- end
- #--------------------------------------------------------------------------
- # * Scroll Up or Down (Map Transition)
- # distance : scroll distance
- #--------------------------------------------------------------------------
- def transition_up_down(distance)
- @display_y = @display_y + distance
- end
- #--------------------------------------------------------------------------
- # * Scroll Left or Right (Map Transition)
- # distance : scroll distance
- #--------------------------------------------------------------------------
- def transition_left_right(distance)
- @display_x = @display_x + distance
- end
- #--------------------------------------------------------------------------
- # * Start Map Transition
- # direction : scroll direction
- # distance : scroll distance
- # speed : scroll speed
- #--------------------------------------------------------------------------
- def start_transition(direction, distance, speed)
- @transition_direction = direction
- @transition_rest = distance
- @transition_speed = speed
- end
- #--------------------------------------------------------------------------
- # * Determine if Transitioning
- #--------------------------------------------------------------------------
- def transitioning?
- return @transition_rest > 0
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # Refresh map if necessary
- if $game_map.need_refresh
- refresh
- end
- # If scrolling
- if @scroll_rest > 0
- # Change from scroll speed to distance in map coordinates
- distance = 2 ** @scroll_speed
- # Execute scrolling
- case @scroll_direction
- when 2 # Down
- scroll_down(distance)
- when 4 # Left
- scroll_left(distance)
- when 6 # Right
- scroll_right(distance)
- when 8 # Up
- scroll_up(distance)
- end
- # Subtract distance scrolled
- @scroll_rest -= distance
- end
- # If transitioning
- if @transition_rest > 0
- # Change from scroll speed to distance in map coordinates
- distance = 2 ** @transition_speed
- # Execute scrolling
- case @transition_direction
- when 2 # Down
- transition_up_down(-1 * distance)
- when 4 # Left
- transition_left_right(distance)
- when 6 # Right
- transition_left_right(-1 * distance)
- when 8 # Up
- transition_up_down(distance)
- end
- # Subtract distance scrolled
- @transition_rest -= distance
- end
- # Update map event
- for event in @events.values
- event.update
- end
- # Update common event
- for common_event in @common_events.values
- common_event.update
- end
- # Manage fog scrolling
- @fog_ox -= @fog_sx / 8.0
- @fog_oy -= @fog_sy / 8.0
- # Manage change in fog color tone
- if @fog_tone_duration >= 1
- d = @fog_tone_duration
- target = @fog_tone_target
- @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
- @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
- @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
- @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
- @fog_tone_duration -= 1
- end
- # Manage change in fog opacity level
- if @fog_opacity_duration >= 1
- d = @fog_opacity_duration
- @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
- @fog_opacity_duration -= 1
- end
- end
- end
- class Game_Character
- attr_accessor :move_speed
- #--------------------------------------------------------------------------
- # * Get Screen X-Coordinates
- #--------------------------------------------------------------------------
- def screen_x(temp=false)
- # Get screen coordinates from real coordinates and map display position
- if temp and !self.is_a?(Game_Player)
- if $game_player.direction == 4
- return (@real_x - $game_map.display_x + 3) / 4 + 16 - 640
- elsif $game_player.direction == 6
- return (@real_x - $game_map.display_x + 3) / 4 + 16 + 640
- end
- end
- return (@real_x - $game_map.display_x + 3) / 4 + 16
- end
- #--------------------------------------------------------------------------
- # * Get Screen Y-Coordinates
- #--------------------------------------------------------------------------
- def screen_y(temp=false)
- # Get screen coordinates from real coordinates and map display position
- if temp and !self.is_a?(Game_Player)
- if $game_player.direction == 2
- y = (@real_y - $game_map.display_y + 3) / 4 + 32 + 480
- elsif $game_player.direction == 8
- y = (@real_y - $game_map.display_y + 3) / 4 + 32 - 480
- end
- end
- y = (@real_y - $game_map.display_y + 3) / 4 + 32 if y == nil
- # Make y-coordinate smaller via jump count
- if @jump_count >= @jump_peak
- n = @jump_count - @jump_peak
- else
- n = @jump_peak - @jump_count
- end
- return y - (@jump_peak * @jump_peak - n * n) / 2
- end
- #--------------------------------------------------------------------------
- # * Get Screen Z-Coordinates
- # height : character height
- #--------------------------------------------------------------------------
- def screen_z(height = 0)
- # If display flag on closest surface is ON
- if @always_on_top
- # 999, unconditional
- return 999
- end
- # Get screen coordinates from real coordinates and map display position
- z = 0#(@real_y - $game_map.display_y + 3) / 4 + 32
- # If tile
- if @tile_id > 0
- # Add tile priority * 32
- return z + $game_map.priorities[@tile_id] * 32
- # If character
- else
- # If height exceeds 32, then add 31
- return z #+ ((height > 32) ? 31 : 0)
- end
- end
- #--------------------------------------------------------------------------
- # * Move Down
- # turn_enabled : a flag permits direction change on that spot
- #--------------------------------------------------------------------------
- def move_down(turn_enabled = true, override = false)
- # Turn down
- if turn_enabled
- turn_down
- end
- # If passable
- if passable?(@x, @y, 2) or override
- # Turn down
- turn_down
- # Update coordinates
- @y += 1
- # Increase steps
- increase_steps
- # If impassable
- else
- # Determine if touch event is triggered
- check_event_trigger_touch(@x, @y+1)
- end
- end
- #--------------------------------------------------------------------------
- # * Move Left
- # turn_enabled : a flag permits direction change on that spot
- #--------------------------------------------------------------------------
- def move_left(turn_enabled = true, override = false)
- # Turn left
- if turn_enabled
- turn_left
- end
- # If passable
- if passable?(@x, @y, 4) or override
- # Turn left
- turn_left
- # Update coordinates
- @x -= 1
- # Increase steps
- increase_steps
- # If impassable
- else
- # Determine if touch event is triggered
- check_event_trigger_touch(@x-1, @y)
- end
- end
- #--------------------------------------------------------------------------
- # * Move Right
- # turn_enabled : a flag permits direction change on that spot
- #--------------------------------------------------------------------------
- def move_right(turn_enabled = true, override = false)
- # Turn right
- if turn_enabled
- turn_right
- end
- # If passable
- if passable?(@x, @y, 6) or override
- # Turn right
- turn_right
- # Update coordinates
- @x += 1
- # Increase steps
- increase_steps
- # If impassable
- else
- # Determine if touch event is triggered
- check_event_trigger_touch(@x+1, @y)
- end
- end
- #--------------------------------------------------------------------------
- # * Move up
- # turn_enabled : a flag permits direction change on that spot
- #--------------------------------------------------------------------------
- def move_up(turn_enabled = true, override = false)
- # Turn up
- if turn_enabled
- turn_up
- end
- # If passable
- if passable?(@x, @y, 8) or override
- # Turn up
- turn_up
- # Update coordinates
- @y -= 1
- # Increase steps
- increase_steps
- # If impassable
- else
- # Determine if touch event is triggered
- check_event_trigger_touch(@x, @y-1)
- end
- end
- #--------------------------------------------------------------------------
- # * 1 Step Forward
- #--------------------------------------------------------------------------
- def move_forward(override=false)
- case @direction
- when 2
- move_down(false,override)
- when 4
- move_left(false,override)
- when 6
- move_right(false,override)
- when 8
- move_up(false,override)
- end
- end
- end
- class Game_Player
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # Remember whether or not moving in local variables
- last_moving = moving?
- # If moving, event running, move route forcing, and message window
- # display are all not occurring
- unless moving? or $game_system.map_interpreter.running? or
- @move_route_forcing or $game_temp.message_window_showing
- # Move player in the direction the directional button is being pressed
- case Input.dir4
- when 2
- if $game_map.valid?(@x, @y+1)
- move_down
- elsif !$game_temp.map_transitioning
- @direction = 2
- $scene.begin_transfer
- end
- when 4
- if $game_map.valid?(@x-1, @y)
- move_left
- elsif !$game_temp.map_transitioning
- @direction = 4
- $scene.begin_transfer
- end
- when 6
- if $game_map.valid?(@x+1, @y)
- move_right
- elsif !$game_temp.map_transitioning
- @direction = 6
- $scene.begin_transfer
- end
- when 8
- if $game_map.valid?(@x, @y-1)
- move_up
- elsif !$game_temp.map_transitioning
- @direction = 8
- $scene.begin_transfer
- end
- end
- end
- # Remember coordinates in local variables
- last_real_x = @real_x
- last_real_y = @real_y
- super
- return if $game_temp.map_transitioning
- # If character moves down and is positioned lower than the center
- # of the screen
- if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
- # Scroll map down
- $game_map.scroll_down(@real_y - last_real_y)
- end
- # If character moves left and is positioned more let on-screen than
- # center
- if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
- # Scroll map left
- $game_map.scroll_left(last_real_x - @real_x)
- end
- # If character moves right and is positioned more right on-screen than
- # center
- if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
- # Scroll map right
- $game_map.scroll_right(@real_x - last_real_x)
- end
- # If character moves up and is positioned higher than the center
- # of the screen
- if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
- # Scroll map up
- $game_map.scroll_up(last_real_y - @real_y)
- end
- # If not moving
- unless moving?
- # If player was moving last time
- if last_moving
- # Event determinant is via touch of same position event
- result = check_event_trigger_here([1,2])
- # If event which started does not exist
- if result == false
- # Disregard if debug mode is ON and ctrl key was pressed
- unless $DEBUG and Input.press?(Input::CTRL)
- # Encounter countdown
- if @encounter_count > 0
- @encounter_count -= 1
- end
- end
- end
- end
- # If C button was pressed
- if Input.trigger?(Input::C)
- # Same position and front event determinant
- check_event_trigger_here([0])
- check_event_trigger_there([0,1,2])
- end
- end
- end
- end
- #==============================================================================
- # ** Sprite_Character
- #------------------------------------------------------------------------------
- # This sprite is used to display the character.It observes the Game_Character
- # class and automatically changes sprite conditions.
- #==============================================================================
- class Character_Sprite < RPG::Sprite
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :character # character
- #--------------------------------------------------------------------------
- # * Object Initialization
- # viewport : viewport
- # character : character (Game_Character)
- #--------------------------------------------------------------------------
- def initialize(viewport, character = nil, section=0, temp=false)
- super(viewport)
- @character = character
- @section = section
- @temp = temp
- update
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- # If tile ID, file name, or hue are different from current ones
- if @tile_id != @character.tile_id or
- @character_name != @character.character_name or
- @character_hue != @character.character_hue
- # Remember tile ID, file name, and hue
- @tile_id = @character.tile_id
- @character_name = @character.character_name
- @character_hue = @character.character_hue
- # If tile ID value is valid
- if @tile_id >= 384
- self.bitmap = RPG::Cache.tile($game_map.tileset_name,
- @tile_id, @character.character_hue)
- self.src_rect.set(0, 0, 32, 32)
- self.ox = 16
- self.oy = 32
- # If tile ID value is invalid
- else
- self.bitmap = RPG::Cache.character(@character.character_name,
- @character.character_hue)
- @cw = bitmap.width / 4
- @ch = bitmap.height / 4
- self.ox = @cw / 2
- self.oy = @ch
- end
- end
- # Set visible situation
- self.visible = (not @character.transparent)
- # If graphic is character
- if @tile_id == 0
- # Set rectangular transfer
- sx = @character.pattern * @cw
- sy = (@character.direction - 2) / 2 * @ch
- if @ch > 32
- ty = sy + @ch - ((@section + 1) * 32)
- if ty > sy
- @th = 32
- else
- @th = 32 + ty - sy
- ty = sy
- end
- else
- ty = sy
- @th = @ch
- end
- self.src_rect.set(sx, ty, @cw, @th)
- self.oy = @th
- end
- # Set sprite coordinates
- self.x = @character.screen_x(@temp)
- self.y = @character.screen_y(@temp) - (@section * 32)
- if $game_temp.map_transitioning
- self.z = @character.screen_z(@ch) + (@section * 32) + (1 - @section)
- else
- self.z = @character.screen_z(@ch) + (@section * 32)
- end
- # Set opacity level, blend method, and bush depth
- self.opacity = @character.opacity
- self.blend_type = @character.blend_type
- self.bush_depth = @section == 0 ? @character.bush_depth : 0
- # Animation
- if @character.animation_id != 0
- animation = $data_animations[@character.animation_id]
- animation(animation, true)
- @character.animation_id = 0
- end
- end
- end
- #==============================================================================
- # ** Sprite_Character
- #------------------------------------------------------------------------------
- # This sprite is used to display the character.It observes the Game_Character
- # class and automatically changes sprite conditions.
- #==============================================================================
- class Sprite_Character
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :character # character
- #--------------------------------------------------------------------------
- # * Object Initialization
- # viewport : viewport
- # character : character (Game_Character)
- #--------------------------------------------------------------------------
- def initialize(viewport, character = nil, temp=false)
- bitmap = RPG::Cache.character(character.character_name, character.character_hue)
- @sprites = []
- for i in 0..(bitmap.height / 4 / 32)
- sprite = Character_Sprite.new(viewport, character, i, temp)
- @sprites << sprite
- end
- @viewport = viewport
- @character = character
- @temp = temp
- end
- #--------------------------------------------------------------------------
- # * Dispose
- #--------------------------------------------------------------------------
- def dispose
- for sprite in @sprites
- sprite.dispose
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- for sprite in @sprites
- sprite.update
- end
- end
- end
- class Spriteset_Map
- alias original_dispose dispose
- alias original_update update
- #--------------------------------------------------------------------------
- # * Dispose
- #--------------------------------------------------------------------------
- def dispose
- if @new_panorama != nil
- # Dispose of panorama plane
- @new_panorama.dispose
- # Dispose of fog plane
- @new_fog.dispose
- # Dispose of character sprites
- for sprite in @new_character_sprites
- sprite.dispose
- end
- end
- original_dispose
- end
- #--------------------------------------------------------------------------
- # * Transition
- #--------------------------------------------------------------------------
- def transition_to(new_sprite_source)
- @new_sprite_source = new_sprite_source
- # Make tilemap
- # make_tilemap_sprites
- @tilemap.prepare_transition(@new_sprite_source, $game_player.direction, @viewport1)
- # Make panorama plane
- @new_panorama = Plane.new(@viewport1)
- @new_panorama.z = -1000
- # Make fog plane
- @new_fog = Plane.new(@viewport1)
- @new_fog.z = 3000
- # Make character sprites
- left_x = @new_sprite_source.display_x / 128
- top_y = @new_sprite_source.display_y / 128
- @new_character_sprites = []
- for i in @new_sprite_source.events.keys.sort
- if (left_x <= @new_sprite_source.events[i].x and @new_sprite_source.events[i].x < left_x + 20) and
- (top_y <= @new_sprite_source.events[i].y and @new_sprite_source.events[i].y < top_y + 15)
- sprite = Sprite_Character.new(@viewport1, @new_sprite_source.events[i], true)
- @new_character_sprites.push(sprite)
- end
- end
- # Frame update
- update
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # Check for Transfer Data
- if @new_panorama != nil
- # If panorama is different from current one
- if @new_panorama_name != @new_sprite_source.panorama_name or
- @new_panorama_hue != @new_sprite_source.panorama_hue
- @new_panorama_name = @new_sprite_source.panorama_name
- @new_panorama_hue = @new_sprite_source.panorama_hue
- if @new_panorama.bitmap != nil
- @new_panorama.bitmap.dispose
- @new_panorama.bitmap = nil
- end
- if @new_panorama_name != ""
- @new_panorama.bitmap = RPG::Cache.panorama(@new_panorama_name, @new_panorama_hue)
- end
- Graphics.frame_reset
- end
- # If fog is different than current fog
- if @new_fog_name != @new_sprite_source.fog_name or
- @new_fog_hue != @new_sprite_source.fog_hue
- @new_fog_name = @new_sprite_source.fog_name
- @new_fog_hue = @new_sprite_source.fog_hue
- if @new_fog.bitmap != nil
- @new_fog.bitmap.dispose
- @new_fog.bitmap = nil
- end
- if @new_fog_name != ""
- @new_fog.bitmap = RPG::Cache.fog(@new_fog_name, @new_fog_hue)
- end
- Graphics.frame_reset
- end
- # Update panorama plane
- @new_panorama.ox = @new_sprite_source.display_x / 8
- @new_panorama.oy = @new_sprite_source.display_y / 8
- # Update fog plane
- @new_fog.zoom_x = @new_sprite_source.fog_zoom / 100.0
- @new_fog.zoom_y = @new_sprite_source.fog_zoom / 100.0
- @new_fog.opacity = @new_sprite_source.fog_opacity
- @new_fog.blend_type = @new_sprite_source.fog_blend_type
- @new_fog.ox = @new_sprite_source.display_x / 4 + @new_sprite_source.fog_ox
- @new_fog.oy = @new_sprite_source.display_y / 4 + @new_sprite_source.fog_oy
- @new_fog.tone = @new_sprite_source.fog_tone
- # Update character sprites
- for sprite in @new_character_sprites
- sprite.update
- end
- end
- original_update
- end
- end
- class Scene_Map
- alias original_update update
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # Loop
- loop do
- # Update map, interpreter, and player order
- # (this update order is important for when conditions are fulfilled
- # to run any event, and the player isn't provided the opportunity to
- # move in an instant)
- $game_map.update
- if $game_temp.map_transitioning
- @transfer_map.update
- end
- $game_system.map_interpreter.update
- $game_player.update
- # Update system (timer), screen
- $game_system.update
- $game_screen.update
- # Abort loop if player isn't place moving
- unless $game_temp.player_transferring
- break
- end
- # Run place move
- transfer_player
- # Abort loop if transition processing
- if $game_temp.transition_processing
- break
- end
- end
- # Update sprite set
- @spriteset.update
- # Update message window
- @message_window.update
- # Check for Map Transition
- if $game_temp.map_transitioning
- unless $game_map.transitioning?
- finish_transfer
- end
- return
- end
- # If game over
- if $game_temp.gameover
- # Switch to game over screen
- $scene = Scene_Gameover.new
- return
- end
- # If returning to title screen
- if $game_temp.to_title
- # Change to title screen
- $scene = Scene_Title.new
- return
- end
- # If transition processing
- if $game_temp.transition_processing
- # Clear transition processing flag
- $game_temp.transition_processing = false
- # Execute transition
- if $game_temp.transition_name == ""
- Graphics.transition(20)
- else
- Graphics.transition(40, "Graphics/Transitions/" +
- $game_temp.transition_name)
- end
- end
- # If showing message window
- if $game_temp.message_window_showing
- return
- end
- # If encounter list isn't empty, and encounter count is 0
- if $game_player.encounter_count == 0 and $game_map.encounter_list != []
- # If event is running or encounter is not forbidden
- unless $game_system.map_interpreter.running? or
- $game_system.encounter_disabled
- # Confirm troop
- n = rand($game_map.encounter_list.size)
- troop_id = $game_map.encounter_list[n]
- # If troop is valid
- if $data_troops[troop_id] != nil
- # Set battle calling flag
- $game_temp.battle_calling = true
- $game_temp.battle_troop_id = troop_id
- $game_temp.battle_can_escape = true
- $game_temp.battle_can_lose = false
- $game_temp.battle_proc = nil
- end
- end
- end
- # If B button was pressed
- if Input.trigger?(Input::B)
- # If event is running, or menu is not forbidden
- unless $game_system.map_interpreter.running? or
- $game_system.menu_disabled
- # Set menu calling flag or beep flag
- $game_temp.menu_calling = true
- $game_temp.menu_beep = true
- end
- end
- # If debug mode is ON and F9 key was pressed
- if $DEBUG and Input.press?(Input::F9)
- # Set debug calling flag
- $game_temp.debug_calling = true
- end
- # If player is not moving
- unless $game_player.moving?
- # Run calling of each screen
- if $game_temp.battle_calling
- call_battle
- elsif $game_temp.shop_calling
- call_shop
- elsif $game_temp.name_calling
- call_name
- elsif $game_temp.menu_calling
- call_menu
- elsif $game_temp.save_calling
- call_save
- elsif $game_temp.debug_calling
- call_debug
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Player Place Move
- #--------------------------------------------------------------------------
- def begin_transfer
- # Set map transition flag
- $game_temp.map_transitioning = true
- # Discover map to transfer to
- new_map_id = $game_map.map_link[$game_player.direction/2]
- # Check for validity
- return if new_map_id == 0
- # Set Up next map
- @transfer_map = Game_Map.new
- @transfer_map.setup(new_map_id)
- @spriteset.transition_to(@transfer_map)
- case $game_player.direction
- when 2 # Moving Down
- @transfer_map.display_x = $game_map.display_x
- @transfer_map.display_y = -1920
- $game_temp.player_new_x = $game_player.x
- $game_temp.player_new_y = 0
- when 4 # Moving Left
- @transfer_map.display_x = 2560
- @transfer_map.display_y = $game_map.display_y
- $game_temp.player_new_x = @transfer_map.width - 1
- $game_temp.player_new_y = $game_player.y
- when 6 # Moving Right
- @transfer_map.display_x = -2560
- @transfer_map.display_y = $game_map.display_y
- $game_temp.player_new_x = 0
- $game_temp.player_new_y = $game_player.y
- when 8 # Moving Up
- @transfer_map.display_x = $game_map.display_x
- @transfer_map.display_y = 1920
- $game_temp.player_new_x = $game_player.x
- $game_temp.player_new_y = @transfer_map.height - 1
- end
- dist = [2,8].include?($game_player.direction) ? 1920 : 2560
- # Begin Transition
- $game_map.start_transition(10 - $game_player.direction, dist, 5)
- @transfer_map.start_transition(10 - $game_player.direction, dist, 5)
- # Move $game_player
- $game_player.move_speed = 1
- $game_player.move_forward(true)
- end
- #--------------------------------------------------------------------------
- # * Player Place Move
- #--------------------------------------------------------------------------
- def finish_transfer
- # Clear map transition flag
- $game_temp.map_transitioning = false
- # Reassign variables
- $game_map.setup(@transfer_map.map_id)
- @transfer_map = nil
- # Set up player position
- $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
- # Update map (run parallel process event)
- $game_map.update
- # Transition Spriteset
- @spriteset.dispose
- @spriteset = Spriteset_Map.new
- # Run automatic change for BGM and BGS set on the map
- $game_map.autoplay
- # Frame reset
- Graphics.frame_reset
- # Update input information
- Input.update
- $game_player.move_speed = 4
- end
- end
Expand to see the code.
Instructions
1) Create a new Script just above main and paste the Tilemap Script
2) Create a new Script above main but below the Tilemap Script and paste the Zelda Scroll Script
3) On any map you'd like to use it on, create an Event an call it "Transfer". I usually like to put it in the upper left corner, but that isn't required.
4) In the Event, create a comment of "<direction>:<map id>" for each edge you would like to connect to the map.
In this case, <direction> is the direction the $game_player would be heading as he left the current map [Left, Right, Up, Down]
<map id> is the ID of the map you want to connect to.
Make sure there are no spaces.
5) Enjoy!
FAQ
I will add to this as questions arise
Compatibility
This script is NOT SDK compatible.
That said, it edits a large number of methods and classes, so I'm sure there will be some compatibility issues.
As a note, it completely rewrites the Sprite_Character class. In also rewrites the update method for Game_Map, Game_Player, and Scene_Map completely.
Credits and Thanks
SephirothSpawn for his Tilemap Class
Author's Notes
This is a rough, general version without alot of thrills or extras. That said, it works pretty well.
If you have any questions or comments, I'd love to hear them. However, I don't stop by this board that often, so I would recommend PMing me or emailing me if you have any pressing concerns. Otherwise, I will reply whenever I happen by.
Terms and Conditions
Feel free to use the scripts however you like, so long as credit is given to SephirothSpawn for the Tilemap Class and myself for the rest. However, please do not post this anywhere else without my permission. Thanks!