#============================================================================ # ** Tilemap Enchance v.0.75 (RGSS3 Version) #============================================================================ # # *HEAVILY EDITED* by LiTTleDRAgo # # This script serves as a complete standard tilemap class replacement and # enables you to access single layers. It's got some new special features # as well. # Basically the script works flawlessly, something that can't be said of most # other tilemap rewrites. # # 1. Installation # # Paste the script above main but below the standard scripts. # # 2. Functional Principle # # Upon entering a map the script loads the new class Tilemap_New instead of Tilemap. # A sprite with bitmap is created for every row of the map in y (from 0 to the # bottom). There's an additional distinction between the single priority settings and # tiles/autotiles. So the tiles are pre-cached and not drawn new during the game. # This requires lots of RAM and increases the maps' load times slightly but improves # performance as well! # # 3. Benefit # # You can directly modify the display process of tiles now, or modify the tile # graphics themselves. Three built-in features are: # Blend types for autotiles (normal, add, sub; useful for certain water/light effects) # Changeable animation speed of autotiles as well as a color tone for the tilemap alone. # Other purposes would be a screen size script. My tilemap class is especially suited # for those due to the performance not diminishing at higher resolutions, or just # marginally. # # 4. Usage # # The script is automatically used after inserting it, however special # features need to be activated seperately: # # - Autotile blend_type/speed: # Configuration via the module Autotile below this introduction. # Possible values for blend_type are 0 (normal), 1 (add), 2 (sub), for # speed every integer can be used. Small numbers mean faster animation # (0 = each frame). # Configuration like so: MAP_ID=>{AUTOTILE_ID=>BLEND_TYPE/BLEND_SPEED} in the # respective section BLEND_TYPE respectively SPEED. Examples are given. # ID goes from 0 to 6 (left to right in the tileset). # # DEFAULT_SPEED is the speed used in case SPEED doesn't contain a value for a map # or an autotile. # # - Tilemap-Tone: # Can be accessed via Call Script or in a script. Use this command: # # $game_map.start_tone_change(tone,duration) # # Whereas tone = Tone.new(r,g,b,gr). This tone affects tiles and autotiles only, # screen color tone can still be added seperately. # # 5. Restrictions # # - Post hoc changes of tile data in the script doesn't have an effect # in this version yet (e.g. via $game_map.data) # # - High memory consumption. Depending on the map size and usage of autotiles # the memory needed can add up to 800 MB. (200*200 map, 1 layer filled with # normal tiles, 1 layer filled with 4 frames autotile) # Realistic footprint accounts to 500 MB max, 512 MB RAM recommended for maps # bigger than 100*100! # # - Increased loading time. Depending on the map size and usage of autotiles # loading time ranges from 0 to 6 seconds. Small maps (30*30) are loaded # instantly, 60*60 with autotiles ca. 1 second, 100*100 with autotiles 2 seconds, # 200*200 map, 1 layer filled with normal tiles, 1 layer filled with 4 frames # autotiles 6 seconds. # # - A teleport to the current map leads to a graphical glitch. # # 6. Pros # # - Full access to all sprites on a map # - Autotile Blend_types and variable speed # - Autotile-Blend_types und variable Geschwindigkeit # - Great performance at memory's cost # - Full functionality (see Restrictions for exceptions) # - Lag doesn't increase when using higher resolutions # # # 7. Credits # # Credits to GodLike for the RPG::Cache extension # English translation by Terv # Edited by LiTTleDRAgo # Feel free to use and modify as you like, however be sure to give credit. # # 8. Changelog # # V 0.75: # # - Compatibility for RGSS3 added # - Load time slightly decreased # - General performance improved # - Small display errors caused by specific autotile combinations fixed # # 9. Contact # # Questions, ideas, bug reports? Please drop me an email: admin@envile-media.at # # #============================================================================ RGSS3 = RUBY_VERSION == '1.9.2' #============================================================================== # ** Module Autotile #------------------------------------------------------------------------------ # # This module contains autotile configurations. # #============================================================================== if true module AUTOTILE # MAP_ID => { AUTOTILE_ID => BLEND_TYPE,.. } BLEND_TYPE = { 4 => { 5=>1, 6=>2 }, } # MAP_ID => { AUTOTILE_ID => SPEED,.. } SPEED = { 4 => { 4 => 2 }, } # DEFAULT_SPEED DEFAULT_SPEED = 4 end #============================================================================== # ** Sprite_Auto NEW #------------------------------------------------------------------------------ # # This class manages autotiles layers. Every layer contains multiple sprites, # one for each autotile column. Furthermore generates respective bitmaps for # the layer. # #============================================================================== class Sprite_Auto attr_reader :cache2 #-------------------------------------------------------------------------- # * Initialize (read tiles, create sprites & bitmaps) #-------------------------------------------------------------------------- def initialize(viewport,tiles,speed,autotile_frames,priority,blend_type) # Store autotile data @tiles = tiles @tileset_id = $game_map.map.tileset_id @tileset = RPG::Cache.tileset($game_map.tileset_name) @speed = speed @priority = priority @autotile_frames = autotile_frames @frames = autotile_frames[tiles[0]] @priorities = $game_map.priorities @blend_type = blend_type @viewport = viewport # Animation variables @time = 0 @state = -1 # Get number of tiles on x/y axis @width = $game_map.width @height = $game_map.height # Set layer border variables to l<->r and u<->d (changed max/min values) @border_lx = @width @border_ty = @height @border_rx = 0 @border_by = 0 # Set row borders @border_lx_row = @width @border_rx_row = 0 # Create table for row borders @rows = Table.new(@height,2) # Hash for sprites & cache @sprites = {} @cache = {} @cache2 = {} # If special blend_type if @blend_type != 0 # Setup tiles accordingly setup_tiles_blend # Else: normal blendig else # Setup tiles setup_tiles end # Return if not valid return if !valid? # Otherwise, create sprites & bitmaps create_sprites # If special blend_type if @blend_type != 0 # Draw blended tiles draw_tiles_blend else # Draw tiles draw_tiles end @tileset = nil end #-------------------------------------------------------------------------- # * Valid? (checks whether found in tiles for this layer) #-------------------------------------------------------------------------- def valid? # If right border greater or equal to left border and # top border greater or equal to bottom border then true return @border_rx >= @border_lx && @border_by >= @border_ty end #-------------------------------------------------------------------------- # * Row_valid? (checks whether found in tiles in column y) #-------------------------------------------------------------------------- def row_valid?(y) # If right border of row equal or greater to left border of row # then true return @rows[y,1] > @rows[y,0] end #-------------------------------------------------------------------------- # * Setup_tiles_blend (reads tiles for this layer and defines the borders. # Makes use of special rules for reading) #-------------------------------------------------------------------------- def setup_tiles_blend # Get pre-sorted tile data with priority of the layer @data_link = $game_map.priority_data(@priority) # Clone hashs, needed for functionally interation while deleting stuff # from the data @data = @data_link.dup @data_link.each_pair do |dx,data_x| dat_x = @data[dx] dat_x = data_x.dup data_x.each_pair do |dz,data_z| dat_x[dz] = data_z.dup end end tiles_found = false layer = 0 # Iterate through sorted tiles on y-axis @data.each_pair do |y,data_y| # Iterate through sorted tiles on x-axis data_y.each_pair do |x,data_x| # Iterate through map editor layers downwards data_x.each_pair do |z,t| # Get Tile ID # Skip to next if there no tile next if t == nil # If tile fits properties of layer, only true if t is a autotile if @tiles.include?(t/48-1) # Add tile id to cache @cache[y] = {} if @cache[y] == nil @cache[y][x] = {} if @cache[y][x] == nil @cache[y][x][z] = t # Extend borders border(x,y) # Delete from map data list @data_link[y][x].delete(z) @data_link[y].delete(x) if @data_link[y][x].size == 0 @data_link.delete(y) if @data_link[y].size == 0 tiles_found = true layer = z end end if tiles_found == true if layer == 0 for z in [1,2] t = data_x[z] next if t == nil || t < 384 || @priorities[t] != @priority @cache2[y] = {} if @cache2[y] == nil @cache2[y][x] = {} if @cache2[y][x] == nil @cache2[y][x][z] = t @data_link[y][x].delete(z) @data_link[y].delete(x) if @data_link[y][x].size == 0 @data_link.delete(y) if @data_link[y].size == 0 end elsif layer == 1 t = data_x[2] next if t == nil || t < 384 || @priorities[t] != @priority @cache2[y] = {} if @cache2[y] == nil @cache2[y][x] = {} if @cache2[y][x] == nil @cache2[y][x][z] = t @data_link[y][x].delete(z) @data_link[y].delete(x) if @data_link[y][x].size == 0 @data_link.delete(y) if @data_link[y].size == 0 end end end # Set row borders @rows[y,0] = @border_lx_row @rows[y,1] = @border_rx_row # Re-Initialize row border temporaries for next iteraton @border_lx_row = @width/32 @border_rx_row = 0 end end #-------------------------------------------------------------------------- # * Setup_tiles (reads tiles for this layer and defines the borders. # Makes use of special rules for reading) #-------------------------------------------------------------------------- def setup_tiles # Get pre-sorted tile data with priority of the layer @data_link = $game_map.priority_data(@priority) # Clone hashs, needed for functionally interation while deleting stuff # from the data @data = @data_link.dup @data_link.each_pair do |dx,data_x| dat_x = @data[dx] dat_x = data_x.dup data_x.each_pair do |dz,data_z| dat_x[dz] = data_z.dup end end # Iterate through sorted tiles on y-axis @data.each_pair do |y,data_y| # Iterate through sorted tiles on x-axis data_y.each_pair do |x,data_x| # Initialize autotile found flag to false autotile_found = false # Iterate through map editor layers downwards data_x.each_pair do |z,t| # Iterate through map editor layers # Get tile id # Store whether tile fits layer properties or not # only true if t is a autotile tiles_include = @tiles.include?(t/48-1) # If tile is included or tile is from tileset or tile is autotile # with 1 frame if tiles_include || (t >= 384 || @autotile_frames[t/48-1] <= 1) # Store in cache @cache[y] = {} if @cache[y] == nil @cache[y][x] = {} if @cache[y][x] == nil @cache[y][x][z] = t # If tile is a autotile and is included if t < 384 && tiles_include # Delete from map data list @data_link[y][x].delete(z) @data_link[y].delete(x) if @data_link[y][x].size == 0 @data_link.delete(y) if @data_link[y].size == 0 # Extend borders border(x,y) # Set autotile found flag to true autotile_found = true end end end # If no autotile was found & row at y is not empty and x-position is not empty if autotile_found == false && @cache[y] != nil && @cache[y][x] != nil # Delete all tiles on x-position from cache @cache[y].delete(x) @cache.delete(y) if @data_link[y].size == 0 end end # Set row borders @rows[y,0] = @border_lx_row @rows[y,1] = @border_rx_row # Re-Initialize row border temporaries for next iteration @border_lx_row = @width/32 @border_rx_row = 0 end end #-------------------------------------------------------------------------- # * Create_Sprites (creates sprites & mitmaps for every row) #-------------------------------------------------------------------------- def create_sprites # Iterate through tiles on y-axis for y in @cache.keys # If row is not valid if !row_valid?(y) # skip to next next end # Calculate row width distx = @rows[y,1] - @rows[y,0] # Create sprite sprite = Sprite.new(@viewport) # Create bitmap with row-width*count of frames sprite.bitmap = Bitmap.new(distx*32*@frames,32) sprite.x = @rows[y,0]*32-$game_map.display_x/4 sprite.y = y*32-$game_map.display_y/4 # Set source rect to frame 0 sprite.src_rect = Rect.new(0,0,distx*32,32) sprite.blend_type = @blend_type # If priority equals 0 if @priority == 0 # Set z to 0, always beyond later created layers sprite.z = 0 else # Set z to base + priority + dosition - display-Position sprite.z = 32 + 32*@priority + 32*y - $game_map.display_y/4 end # Add sprite to hash @sprites[y] = sprite end end #-------------------------------------------------------------------------- # * Border (enhances the borders of the layer and the current row) #-------------------------------------------------------------------------- def border(x,y) # If X is outside left border if x < @border_lx # Extend left border to x @border_lx = x end # If X is outside right border if x > @border_rx # Extend right border to x+1 @border_rx = x+1 end # If Y is outside top border if y < @border_ty # Extend top border to y @border_ty = y end # If Y is outside bottom border if y > @border_by # Extend bottom_border to y @border_by = y end # If X is outside left row border if x < @border_lx_row # Extend left row border to x @border_lx_row = x end # If X is outside right row border if x+1 > @border_rx_row # Extend right row border to y @border_rx_row = x+1 end end #-------------------------------------------------------------------------- # * Update (updates row's position in the image as well as animations) #-------------------------------------------------------------------------- def update(ox,oy) # Get first and last row 1 outside screen dy = oy/32.0 l = [dy.to_i-1,@border_ty].max r = [dy.to_i+17,@border_by].min # If time exceedes speed if @time > @speed # Reinit time, advance state @time = 0 @state += 1 # Iterate through every row on screen for i in l..r # Skip to next If row has no sprite sprite = @sprites[i] next if sprite == nil || sprite.disposed? || !$game_map.tone # Set sprite properties sprite.tone = $game_map.tone# if @blend_type == 0 sprite.x = @rows[i,0]*32-ox sprite.y = i*32-oy sprite.zoom_x = $game_map.zoom_x || 1.0 sprite.zoom_y = $game_map.zoom_y || 1.0 sprite.x = (sprite.x * sprite.zoom_x) sprite.y = (sprite.y * sprite.zoom_y) # If priority equals 0 if @priority == 0 # Set Z to 0, always beyond later created tiles sprite.z = 0 else # Set Z to Base + Priority + Position - Tilemap position sprite.z = 32 + 32*@priority + i*32 - oy end sprite.z *= ((sprite.zoom_x + sprite.zoom_y) / 2) # Get row width lx = @rows[i,0] w = @rows[i,1] - lx # Set animation frame sprite.src_rect = Rect.new(@state*w*32,0,w*32,32) end # If state exceeded frame count if @state >= @frames-1 # Reset state @state = -1 end # Else: just update position else # Iterate through every row on screen for i in l..r # Skip to next if row has no sprite sprite = @sprites[i] next if sprite == nil || sprite.disposed? || !$game_map.tone # Set sprite properties sprite.tone = $game_map.tone# if @blend_type == 0 sprite.x = @rows[i,0]*32-ox sprite.y = i*32-oy sprite.zoom_x = $game_map.zoom_x || 1.0 sprite.zoom_y = $game_map.zoom_y || 1.0 sprite.x = (sprite.x * sprite.zoom_x) sprite.y = (sprite.y * sprite.zoom_y) # If priority equals 0 if @priority == 0 # Set Z to 0, always beyond later created tiles sprite.z = 0 else # Set Z to Base + Priority + Position - Tilemap position sprite.z = 32 + 32*@priority + i*32 - oy end sprite.z *= ((sprite.zoom_x + sprite.zoom_y) / 2) end end # Advance time @time += 1 end #-------------------------------------------------------------------------- # * Refresh (refreshes all row's properties) #-------------------------------------------------------------------------- def refresh # Iterate through all sprites for y in @cache.keys # Skip if sprite doesn't exist sprite = @sprites[y] next if sprite == nil sprite.tone = $game_map.tone if $game_map.tone # If priority equals 0 sprite.x = @rows[y,0]*32-$game_map.display_x/4 sprite.y = y*32-$game_map.display_y/4 sprite.zoom_x = $game_map.zoom_x || 1.0 sprite.zoom_y = $game_map.zoom_y || 1.0 sprite.x = (sprite.x * sprite.zoom_x) sprite.y = (sprite.y * sprite.zoom_y) if @priority == 0 # Set z to 0, always beyond sprite.z = 0 else # Set Z to Base + Priority + Position - Screen Position sprite.z = 32+32*@priority+y*32-$game_map.display_y/4 end sprite.z *= ((sprite.zoom_x + sprite.zoom_y) / 2) end end #-------------------------------------------------------------------------- # * Draw_tiles_blend (draws the complete layer in the single rows. Makes # use of special rules for 1/2-blended autotiles) #-------------------------------------------------------------------------- def draw_tiles_blend # Iterate through cached tiles on y axis @cache.each_pair do |y,cache_y| sprite = @sprites[y] next if cache_y == nil lx = @rows[y,0] w = @rows[y,1]-lx cache_y.each_pair do |x,cache_x| x_values = RGSS3 ? cache_x.values.reverse : cache_x.values x_values.each do |t| #RGSS3 file = (t / 48) - 1 a = t - (file+1)*48 for f in 0...@frames autotile = RPG::Cache.atile($game_map.autotile_names[file],a,f) sprite.bitmap.blt(-lx*32+x*32+f*w*32,0,autotile,autotile.rect) end end end end RPG::Cache.clear_auto end #-------------------------------------------------------------------------- # * Draw_tiles #-------------------------------------------------------------------------- def draw_tiles @cache.each_pair do |y,cache_y| sprite = @sprites[y] lx = @rows[y,0] w = @rows[y,1]-lx cache_y.each_pair do |x,cache_x| x_values = RGSS3 ? cache_x.keys.reverse : cache_x.keys x_values.each do |z| #RGSS3 t = cache_x[z] if t < 384 file = (t / 48) - 1 a = t - (file+1)*48 for f in 0...@frames autotile = RPG::Cache.atile($game_map.autotile_names[file],a,f) sprite.bitmap.blt(-lx*32+x*32+f*w*32,0,autotile,autotile.rect) end if @autotile_frames[file] <= 1 @data_link[y][x].delete(z) @data_link[y].delete(x) if @data_link[y][x].size == 0 @data_link.delete(y) if @data_link[y].size == 0 end else t -=384 xt = t%8 yt = t/8 r = Rect.new(xt*32,yt*32,32,32) for f in 0...@frames sprite.bitmap.blt(-lx*32+x*32+f*w*32,0,@tileset,r) end @data_link[y][x].delete(z) @data_link[y].delete(x) if @data_link[y][x].size == 0 @data_link.delete(y) if @data_link[y].size == 0 end end end end RPG::Cache.clear_auto end #-------------------------------------------------------------------------- # * Frame Dispose #-------------------------------------------------------------------------- def dispose @sprites.each_value {|sprite| sprite.dispose } end end module RPG module Cache [[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],[13,18,43,48]] AUTOTILES = [26, 27, 32, 33, 4, 27, 32, 33, # 1 26, 5, 32, 33, 4, 5, 32, 33, # 3 26, 27, 32, 11, 4, 27, 32, 11, # 5 26, 5, 32, 11, 4, 5, 32, 11, # 7 26, 27, 10, 33, 4, 27, 10, 33, # 9 26, 5, 10, 33, 4, 5, 10, 33, # 11 26, 27, 10, 11, 4, 27, 10, 11, # 13 26, 5, 10, 11, 4, 5, 10, 11, # 15 24, 25, 30, 31, 24, 5, 30, 31, # 17 24, 25, 30, 11, 24, 5, 30, 11, # 19 14, 15, 20, 21, 14, 15, 20, 11, # 21 14, 15, 10, 21, 14, 15, 10, 11, # 23 28, 29, 34, 35, 28, 29, 10, 35, # 25 4, 29, 34, 35, 4, 29, 10, 35, # 27 38, 39, 44, 45, 4, 39, 44, 45, # 29 38, 5, 44, 45, 4, 5, 44, 45, # 31 24, 29, 30, 35, 14, 15, 44, 45, # 33 12, 13, 18, 19, 12, 13, 18, 11, # 35 16, 17, 22, 23, 16, 17, 10, 23, # 37 40, 41, 46, 47, 4, 41, 46, 47, # 39 36, 37, 42, 43, 36, 5, 42, 43, # 41 12, 17, 18, 23, 12, 13, 42, 43, # 43 36, 41, 42, 47, 16, 17, 46, 47, # 45 12, 17, 42, 47, 0, 1, 6, 7] # 47 module_function def atile(file, id , offset) @auto_cache ||= {} if @auto_cache[[file,id,offset]] == nil autotile_bitmap = Bitmap.new(32, 32) autotiles_bitmap = autotile(file) if autotiles_bitmap.height == 32 if offset*32 >= autotiles_bitmap.width autotile_bitmap.blt(0,0,autotiles_bitmap,Rect.new(0,0,32,32)) else autotile_bitmap.blt(0,0,autotiles_bitmap,Rect.new(offset*32,0,32,32)) end @auto_cache[[file,id,offset]] = autotile_bitmap return autotile_bitmap end real_id = id*4 off = offset*96 if off>=autotiles_bitmap.width off = 0 end auto1 = AUTOTILES.at(real_id + 0) auto2 = AUTOTILES.at(real_id + 1) auto3 = AUTOTILES.at(real_id + 2) auto4 = AUTOTILES.at(real_id + 3) rect1 = Rect.new(auto1 % 6 * 16 + off, auto1 / 6 * 16, 16, 16) rect2 = Rect.new(auto2 % 6 * 16 + off, auto2 / 6 * 16, 16, 16) rect3 = Rect.new(auto3 % 6 * 16 + off, auto3 / 6 * 16, 16, 16) rect4 = Rect.new(auto4 % 6 * 16 + off, auto4 / 6 * 16, 16, 16) autotile_bitmap.blt(0, 0, autotiles_bitmap, rect1) autotile_bitmap.blt(16, 0, autotiles_bitmap, rect2) autotile_bitmap.blt(0, 16, autotiles_bitmap, rect3) autotile_bitmap.blt(16, 16, autotiles_bitmap, rect4) @auto_cache[[file,id,offset]] = autotile_bitmap end return @auto_cache[[file,id,offset]] end def clear_auto @auto_cache ||= {} @auto_cache.values.each {|bitmap| bitmap.dispose} @auto_cache.clear #GC.start end end end #============================================================================== # ** Sprite_Layer NEW #------------------------------------------------------------------------------ # # This class manages tile layers. Every layer contains multipe sprites, one # for each tile row. Furthermore creates the respective bitmaps for the layer. # #============================================================================== class Sprite_Layer #-------------------------------------------------------------------------- # * Initialize (read tiles, create sprites & bitmaps) #-------------------------------------------------------------------------- def initialize(viewport,priority,autotile_frames,cache=nil) # Get Tileset ID @tileset_id = $game_map.map.tileset_id # Class variables @priority = priority @autotile_frames = autotile_frames @viewport = viewport # Calculate number of tiles on x and y axis @width = $game_map.width @height = $game_map.height # Cache for the tiles if cache == nil @cache = {} else @cache = cache end # Set layer border variables to l<->r and u<->d (changed max/min values) @border_lx = @width @border_ty = @height @border_rx = 0 @border_by = 0 # Row border @border_lx_row = @width @border_rx_row = 0 # Table to store left and right border of every row @rows = Table.new(@height,2) # Hash for the sprites @sprites = {} # Setup tiles if @cache.size == 0 setup_tiles else setup_tiles_cache end # If not valid, return return if !valid? # Otherwise, create sprites create_sprites # Get tileset graphic @tileset = RPG::Cache.tileset($game_map.tileset_name) # Draw tiles draw_tiles @tileset = nil end #-------------------------------------------------------------------------- # * Valid? (checks whether found in tiles for this layer) #-------------------------------------------------------------------------- def valid? # If right border greater or equal to left border and # top border greater or equal to bottom border then true return @border_rx >= @border_lx && @border_by >= @border_ty end #-------------------------------------------------------------------------- # * Row_valid? (checks whether found in tiles in row y) #-------------------------------------------------------------------------- def row_valid?(y) # If right row border is greater than left row border true return @rows[y,1]>@rows[y,0] end #-------------------------------------------------------------------------- # * Setup_tiles (reads tiles for this layer and defines the borders) #-------------------------------------------------------------------------- def setup_tiles # Get pre-sorted Tile data with priority of the layer @data_link = $game_map.priority_data(@priority) # Clone hashs, needed for functionally interation while deleting stuff # from the data @data = @data_link.clone @data_link.each_pair do |dx,data_x| dat_x = @data[dx] dat_x = data_x.dup data_x.each_pair do |dz,data_z| dat_x[dz] = data_z.dup end end # Iterate through sorted tiles on y-axis @data.each_pair do |y,data_y| # Iterate through sorted tiles on x-axis data_y.each_pair do |x,data_x| # Iterate through map editor layers downwards data_x.each_pair do |z,t| # Get Tile ID # If tile is from tileset or autotile with 1 frame if t >= 384 || @autotile_frames[t/48-1] <= 1 # Store in cache @cache[y] = {} if @cache[y] == nil @cache[y][x] = {} if @cache[y][x] == nil @cache[y][x][z] = t # Extend border border(x,y) # Delete from sorted tile list #@data_link[y][x].delete(z) #@data_link[y].delete(x) if @data_link[y][x].size == 0 #@data_link.delete(y) if @data_link[y].size == 0 end end end # Set row borders @rows[y,0] = @border_lx_row @rows[y,1] = @border_rx_row # Re-Initialize row borders for next iteration @border_lx_row = @width/32 @border_rx_row = 0 end end #-------------------------------------------------------------------------- # * Setup_tiles_Cache #-------------------------------------------------------------------------- def setup_tiles_cache # Get pre-sorted Tile data with priority of the layer @data_link = $game_map.priority_data(@priority) # Clone hashs, needed for functionally interation while deleting stuff # from the data @data = @data_link.clone @data_link.each_pair do |dx,data_x| dat_x = @data[dx] dat_x = data_x.dup data_x.each_pair do |dz,data_z| dat_x[dz] = data_z.dup end end # Iterate through sorted tiles on y-axis @cache.each_pair do |y,cache_y| # Iterate through sorted tiles on x-axis cache_y.each_pair do |x,cache_x| # Iterate through map editor layers border(x,y) if cache_x.size > 0 end # Set row borders @rows[y,0] = @border_lx_row @rows[y,1] = @border_rx_row # Re-Initialize row borders for next iteration @border_lx_row = @width/32 @border_rx_row = 0 end end #-------------------------------------------------------------------------- # * Create_Sprites (creates sprites & bitmaps for each row) #-------------------------------------------------------------------------- def create_sprites # Iterate from upper border to lower border for y in @border_ty..@border_by # If row is not valid if !row_valid?(y) # Skip to next next end # Otherwise, calculate distance from left to right border distx = @rows[y,1] - @rows[y,0] # Create sprite sprite = Sprite.new(@viewport) # Create bitmap in row-size sprite.bitmap = Bitmap.new(distx*32,32) # Set x-coordinate to left border sprite.x = @rows[y,0]*32-$game_map.display_x/4 # Set y-coordinate to row y sprite.y = y*32-$game_map.display_y/4 sprite.blend_type = 0 # If priority equals 0 if @priority == 0 # Set Z to 0, Sprite always beyond later created sprite.z = 0 else # Set Z to Base + Priority + Position - Screen Position sprite.z = 32 + 32*@priority + y*32 - $game_map.display_y/4 end # Add sprite to hash @sprites[y] = sprite end end #-------------------------------------------------------------------------- # * Border (enhances borders of layer and current row) #-------------------------------------------------------------------------- def border(x,y) # If X is outside left border if x < @border_lx # Extend left border to x @border_lx = x end # If X is outside right border if x > @border_rx # Extend right border to x+1 @border_rx = x+1 end # If Y is outside top border if y < @border_ty # Extend top border to y @border_ty = y end # If Y is outside bottom border if y > @border_by # Extend bottom_border to y @border_by = y end # If X is outside left row border if x < @border_lx_row # Extend left row border to x @border_lx_row = x end # If X is outside right row border if x+1 > @border_rx_row # Extend right row border to y @border_rx_row = x+1 end end #-------------------------------------------------------------------------- # * Update (updates position of image's rows) #-------------------------------------------------------------------------- def update(ox,oy) # Get uppermost row 1 block outside of screen y = [((oy*4-224)/128).to_i,@border_ty].max # Get lowermost row 1 block outside of screen y2 = [y+17,@border_by].min # Iterate from uppermost to lowermost row for i in y..y2 # Skip if row has no sprite sprite = @sprites[i] next if sprite == nil || sprite.disposed? || !$game_map.tone sprite.tone = $game_map.tone # If priority equals 0 sprite.x = @rows[i,0]*32-ox sprite.y = i*32-oy sprite.zoom_x = $game_map.zoom_x || 1.0 sprite.zoom_y = $game_map.zoom_y || 1.0 sprite.x = (sprite.x * sprite.zoom_x) sprite.y = (sprite.y * sprite.zoom_y) if @priority == 0 # Set z to 0, always beyond sprite.z = 0 else # Set Z to Base + Priority + Position - Screen Position sprite.z = 32+32*@priority+i*32-oy end sprite.z *= ((sprite.zoom_x + sprite.zoom_y) / 2) end end #-------------------------------------------------------------------------- # * Refresh (refreshes all sprites' properties) #-------------------------------------------------------------------------- def refresh # Iterate through all sprites for y in @cache.keys sprite = @sprites[y] # Skip if sprite doesn't exist next if sprite == nil sprite.tone = $game_map.tone if $game_map.tone # If priority equals 0 sprite.x = @rows[y,0]*32-$game_map.display_x/4 sprite.y = y*32-$game_map.display_y/4 sprite.zoom_x = $game_map.zoom_x || 1.0 sprite.zoom_y = $game_map.zoom_y || 1.0 sprite.x = (sprite.x * sprite.zoom_x) sprite.y = (sprite.y * sprite.zoom_y) if @priority == 0 # Set z to 0, always beyond sprite.z = 0 else # Set Z to Base + Priority + Position - Screen Position sprite.z = 32+32*@priority+y*32-$game_map.display_y/4 end sprite.z *= ((sprite.zoom_x + sprite.zoom_y) / 2) end end #-------------------------------------------------------------------------- # * Draw_tiles (draws the complete layer into the single rows) #-------------------------------------------------------------------------- def draw_tiles # Iterate through all cached tiles on y-axis @cache.each_pair do |y,cache_y| # Iterate through all cached tiles on x-axis sprite = @sprites[y] cache_y.each_pair do |x,cache_x| x_values = RGSS3 ? cache_x.values.reverse : cache_x.values # Iterate through all cached tile layers (map-editor) # ! Lowest z first ! x_values.each do |t| #RGSS3 # Get tile ID from cache # Get left border of row lx = @rows[y,0] # If tile is from tileset if t >= 384 # Calculate x/y-position on tileset t -= 384 xt = t%8 yt = t/8 # Source rect r = Rect.new(xt*32,yt*32,32,32) # Blt tile from tileset to row on -border+x sprite.bitmap.blt(-lx*32+x*32,0,@tileset,r) # Else: Tile is an autotile (with 1 frame) else # Calculate file id and autotile id file = (t / 48) - 1 a = t - (file+1)*48 # Get autotile bitmap from RPG::Cache autotile = RPG::Cache.atile($game_map.autotile_names[file],a,0) # Blt autotile to row on -border+x sprite.bitmap.blt(-lx*32+x*32,0,autotile,autotile.rect) end end end end # Clear autotile cache RPG::Cache.clear_auto end #-------------------------------------------------------------------------- # * Dispose (delete row sprites) #-------------------------------------------------------------------------- def dispose # Dispose every sprite for sprite in @sprites.values sprite.dispose end end end #============================================================================== # ** Tilemap_New NEW #------------------------------------------------------------------------------ # # This is the script's core, the new tilemap class. Currently contains methods # for updating and deleting, mostly self-managing. # Creates up to 5 layers and 6 autotile layers. Layers are created depending # on priority and mapping, autotile layer depending on properties of autotiles # (speed,frames,blend mode). # #============================================================================== class Tilemap_New #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :tileset,:autotiles,:viewport attr_reader :autotile_frames #-------------------------------------------------------------------------- # * Initialize (create layer) #-------------------------------------------------------------------------- def initialize(viewport,tileset,autiles) # Save tileset & autotiles @viewport = viewport @tileset = tileset @autotiles = autiles # Get number of frames per autotile @autotile_frames = [] for autotile in @autotiles # If autotiles height exceeds 32 if autotile.height > 32 @autotile_frames << autotile.width/96 # Else: autotiles in X*32 format else @autotile_frames << autotile.width/32 end end # Tileset ID id = $game_map.map.tileset_id # Temporaries autotiles = [] done = [] autotiles_later = {} # Class variables @autotile_layers = [] @layers = [] @ox = 0 @oy = 0 # Iterate through autotiles for i in 0..6 # Get frames frames = @autotile_frames[i] # If only one frame => static, skip next if frames <= 1 || done.include?(i) # Get properties speed = AUTOTILE::SPEED[id][i] if AUTOTILE::SPEED[id] != nil speed = AUTOTILE::DEFAULT_SPEED if speed == nil blend_type = AUTOTILE::BLEND_TYPE[id][i] if AUTOTILE::BLEND_TYPE[id] != nil blend_type = 0 if blend_type == nil priority = $game_map.priorities[(i+1)*48] # Iterate through all autotiles >= current one # Batches similar autotiles in the same layer -> less memody/lag for j in i..6 # Get 2nd autotile properties speed2 = AUTOTILE::SPEED[id][j] if AUTOTILE::SPEED[id] != nil speed2 = AUTOTILE::DEFAULT_SPEED if speed2 == nil frames2 = @autotile_frames[j] blend_type2 = AUTOTILE::BLEND_TYPE[id][j] if AUTOTILE::BLEND_TYPE[id] != nil blend_type2 = 0 if blend_type2 == nil priority2 = $game_map.priorities[(j+1)*48] # If properties of both autotiles match if speed2 == speed && frames2 == frames && blend_type2 == blend_type && priority2 == priority # Store autotile id autotiles << j # Store properties speed3 = speed frames3 = frames priority3 = priority blend_type3 = blend_type # Autotile id is done done << j end end # If special blended autotiles if blend_type3 >= 1 # Store autotile ids & properties for later creation (z-priority) autotiles_later[priority3] = [] if autotiles_later[priority3] == nil autotiles_later[priority3] << Command_Autotile.new(autotiles,speed3,@autotile_frames,priority3,blend_type3) # Else : Normal blended tile else # Create autotile-Layer @autotile_layers << Sprite_Auto.new(@viewport,autotiles,speed3,@autotile_frames,priority3,blend_type3) # Delete if not valid @autotile_layers.delete_at(@autotile_layers.size-1) if !@autotile_layers[@autotile_layers.size-1].valid? end autotiles.clear end # Iterate through all priority layers for i in 0..5 # Create layer sprite sprite = Sprite_Layer.new(@viewport,i,@autotile_frames) # Keep sprite onty if valid? @layers << sprite if sprite.valid? # If blended autotile waits for creation at current priority if autotiles_later[i] != nil # Iterate through autotile commands for c in autotiles_later[i] # Create autotile-layer @autotile_layers << Sprite_Auto.new(@viewport,c.autotiles,c.speed,c.frames,c.priority,c.blend_type) # Delete if not valid @autotile_layers.delete_at(@autotile_layers.size-1) if !@autotile_layers[@autotile_layers.size-1].valid? end # Delete command layer autotiles_later.delete(i) end end end #-------------------------------------------------------------------------- # * Ox (returns tilemap x-position) #-------------------------------------------------------------------------- def ox return @ox end #-------------------------------------------------------------------------- # * Oy (returns tilemap y-position) #-------------------------------------------------------------------------- def oy return @oy end #-------------------------------------------------------------------------- # * Ox= (sets tilemap x-position) #-------------------------------------------------------------------------- def ox=(ox) # Return if position is equal to new position return if @ox == ox @ox = ox end #-------------------------------------------------------------------------- # * Oy= (sets tilemap y-position) #-------------------------------------------------------------------------- def oy=(oy) # Return if position is equal to new position return if @oy == oy @oy = oy end #-------------------------------------------------------------------------- # * Initialize (position,frames,z-position) #-------------------------------------------------------------------------- def update # Update viewport. Corrupts standard x/y positions of fog,characters,weather, # panorama, corrected in the corresponding method #@viewport.ox = $game_map.display_x/4 #@viewport.oy = $game_map.display_y/4 # Update autotile_layers @autotile_layers.each {|layer| layer.update(@ox,@oy)} # Update_layers @layers.each {|layer| layer.update(@ox,@oy)} end #-------------------------------------------------------------------------- # * Dispose (delete layer & autotile layer) #-------------------------------------------------------------------------- def dispose # Dispose autotile layers @autotile_layers.each {|layer| layer.dispose } @autotile_layers = [] # Dispose layers @layers.each {|layer| layer.dispose } @layers = [] end #-------------------------------------------------------------------------- # * Initialize (updates all rows of all layers) #-------------------------------------------------------------------------- def refresh @autotile_layers.each {|layer| layer.refresh} @layers.each {|layer| layer.refresh} end end #============================================================================== # ** Command_Autotile NEW #------------------------------------------------------------------------------ # This class saves all autotile data. Used in order to create autotiles with # blend-mode 1/2 after normal tile layer. #============================================================================== class Command_Autotile #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :autotiles,:speed,:frames,:blend_type,:priority #-------------------------------------------------------------------------- # * Initialize #-------------------------------------------------------------------------- def initialize(autotiles,speed,frames,priority,blend_type) @autotiles = autotiles.clone #Autotile list @speed = speed #Animation speed @frames = frames #Nr. of frames @blend_type = blend_type #Blend type @priority = priority #Priority end end #============================================================================== # ** Game_Temp EDIT #------------------------------------------------------------------------------ # Addon for saving the tilemap upon switching scene. #============================================================================== class Game_Temp attr_accessor :store_tilemap attr_accessor :tilemap end #============================================================================== # ** Spriteset_Map EDIT #------------------------------------------------------------------------------ # Enhances the class Spriteset_Map. Creates an Tilemap new object. Overwrites # initialize, dispose and update methods. # #============================================================================== class Spriteset_Map #-------------------------------------------------------------------------- # * Public Instance_Variables #-------------------------------------------------------------------------- attr_reader :tilemap attr_reader :viewport1 if !method_defined?(:create_tilemap) || !method_defined?(:create_viewports) #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize create_viewports create_tilemap create_panorama create_fog create_characters create_player create_weather create_pictures create_timer update end #-------------------------------------------------------------------------- # * Panorama Initialization #-------------------------------------------------------------------------- def create_panorama @panorama = Plane.new(@viewport1) # Make panorama plane @panorama.z = -1000 end #-------------------------------------------------------------------------- # * Fog Initialization #-------------------------------------------------------------------------- def create_fog @fog = Plane.new(@viewport1) # Make fog plane @fog.z = 3000 end #-------------------------------------------------------------------------- # * Character Sprite Initialization #-------------------------------------------------------------------------- def create_characters @character_sprites = [] for i in $game_map.events.keys.sort # Make character sprites sprite = Sprite_Character.new(@viewport1, $game_map.events[i]) @character_sprites.push(sprite) end end #-------------------------------------------------------------------------- # * Player Initialization #-------------------------------------------------------------------------- def create_player @character_sprites.push(Sprite_Character.new(@viewport1, $game_player)) end #-------------------------------------------------------------------------- # * Weather Initialization #-------------------------------------------------------------------------- def create_weather @weather = RPG::Weather.new(@viewport1) # Make weather end #-------------------------------------------------------------------------- # * Picture Initialization #-------------------------------------------------------------------------- def create_pictures @picture_sprites = [] for i in 1..50 # Make picture sprites @picture_sprites.push(Sprite_Picture.new(@viewport2, $game_screen.pictures[i])) end end #-------------------------------------------------------------------------- # * Timer Initialization #-------------------------------------------------------------------------- def create_timer @timer_sprite = Sprite_Timer.new # Make timer sprite end end #-------------------------------------------------------------------------- # * Viewport Initialization #-------------------------------------------------------------------------- def create_viewports #@viewport1 = Viewport.new(0, 0, 640, 480) # Make viewports @viewport2 = Viewport.new(0, 0, 640, 480) @viewport3 = Viewport.new(0, 0, 640, 480) @viewport2.z = 200 @viewport3.z = 5000 end #-------------------------------------------------------------------------- # * Tilemap Initialization #-------------------------------------------------------------------------- def create_tilemap if $game_temp.tilemap == nil # Make tilemap @viewport1 = Viewport.new(0, 0, 640, 480) # Make Viewport1 redraw_tilemap else # Else: Tilemap is stored @tilemap = $game_temp.tilemap # Load Tilemap & Viewport @viewport1 = @tilemap.viewport @viewport1.visible = true $game_temp.tilemap = nil # Remove tilemap from storage end end #-------------------------------------------------------------------------- # * redraw_tilemap #-------------------------------------------------------------------------- def redraw_tilemap @tilemap.dispose if @tilemap for i in 0..6 autotile_name = $game_map.autotile_names[i].dup (autotiles ||= []) << RPG::Cache.autotile(autotile_name) end tileset = RPG::Cache.tileset($game_map.tileset_name) @tilemap = Tilemap_New.new(@viewport1,tileset,autotiles) end #-------------------------------------------------------------------------- # * Dispose #-------------------------------------------------------------------------- if !method_defined?(:dispose_tilemap) || !method_defined?(:dispose_viewports) def dispose dispose_tilemap dispose_fog dispose_panorama dispose_characters dispose_weather dispose_pictures dispose_timer dispose_viewports end #-------------------------------------------------------------------------- # * Dispose Fog #-------------------------------------------------------------------------- def dispose_fog @fog.dispose end #-------------------------------------------------------------------------- # * Dispose Panorama #-------------------------------------------------------------------------- def dispose_panorama @panorama.dispose end #-------------------------------------------------------------------------- # * Dispose Character Sprite #-------------------------------------------------------------------------- def dispose_characters @character_sprites.each {|sprite| sprite.dispose } end #-------------------------------------------------------------------------- # * Dispose Weather #-------------------------------------------------------------------------- def dispose_weather @weather.dispose end #-------------------------------------------------------------------------- # * Dispose Picture Sprite #-------------------------------------------------------------------------- def dispose_pictures @picture_sprites.compact.each {|sprite| sprite.dispose } end #-------------------------------------------------------------------------- # * Dispose Timer Sprite #-------------------------------------------------------------------------- def dispose_timer @timer_sprite.dispose end end #-------------------------------------------------------------------------- # * Dispose Tilemap #-------------------------------------------------------------------------- def dispose_tilemap @tilemap.tileset.dispose (0..6).each {|i| @tilemap.autotiles[i].dispose } if $game_temp.store_tilemap == true # If tilemap should be stored $game_temp.tilemap = @tilemap.clone # Store tilemap $game_temp.store_tilemap = false # Disable storage flag @viewport1.visible = false else # Else @tilemap.dispose # Dispose tilemap & viewport @viewport1.dispose end end #-------------------------------------------------------------------------- # * Dispose Viewport #-------------------------------------------------------------------------- def dispose_viewports #@viewport1.dispose @viewport2.dispose @viewport3.dispose end end #============================================================================== # ** Game_Map EDIT #------------------------------------------------------------------------------ # Enhances the class Game_Map in order to presort tiles by priority; used for # tilemap tone. #============================================================================== class Game_Map #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_writer :zoom_x attr_writer :zoom_y attr_reader :map # Map-Daten attr_reader :tone # Color-Tone attr_accessor :need_redraw #-------------------------------------------------------------------------- # * Alias Method #-------------------------------------------------------------------------- alias_method :init_later, :initialize alias_method :setup_later, :setup alias_method :upd_later, :update define_method(:zoom_x) { @zoom_x ||= 1.0 } define_method(:zoom_y) { @zoom_y ||= 1.0 } #-------------------------------------------------------------------------- # * Initialize (variables for tilemap tone) #-------------------------------------------------------------------------- def initialize init_later @tone = Tone.new(0,0,0,0) # Tilemap-tone @tone_duration = 0 # Tone-duration @need_redraw = false end #-------------------------------------------------------------------------- # * Setup #-------------------------------------------------------------------------- def setup(map_id) setup_later(map_id) sort # Sort tiles after setup end #-------------------------------------------------------------------------- # * Sort (sorts tile IDs by priority for later reading) #-------------------------------------------------------------------------- def sort @priority0 = {} # One hash for every priority @priority1 = {} @priority2 = {} @priority3 = {} @priority4 = {} @priority5 = {} for x in 0...width # Iterate through tiles on x-axis for y in 0...height # Iterate through tiles on y-axis for z in z_data # Check layers from map editor top->bottom tile = data[x,y,z] # Tile ID if tile != 0 # If tile is not empty # Get & check priority for tile, set in according hash case @priorities[tile] when 0 @priority0[y] ||= {} @priority0[y][x] ||= {} @priority0[y][x][z] = tile when 1 @priority1[y] ||= {} @priority1[y][x] ||= {} @priority1[y][x][z] = tile when 2 @priority2[y] ||= {} @priority2[y][x] ||= {} @priority2[y][x][z] = tile when 3 @priority3[y] ||= {} @priority3[y][x] ||= {} @priority3[y][x][z] = tile when 4 @priority4[y] ||= {} @priority4[y][x] ||= {} @priority4[y][x][z] = tile when 5 @priority5[y] ||= {} @priority5[y][x] ||= {} @priority5[y][x][z] = tile end end end end end end #-------------------------------------------------------------------------- # * Priority-Data (returns previously sorted tiles) #-------------------------------------------------------------------------- def priority_data(priority) case priority # Check priority and return appropriate sorted hash when 0 then return @priority0 when 1 then return @priority1 when 2 then return @priority2 when 3 then return @priority3 when 4 then return @priority4 when 5 then return @priority5 else return @priority0 # Invalid priority: return hash 0 end end #-------------------------------------------------------------------------- # * New Method : z_data #-------------------------------------------------------------------------- unless method_defined?(:z_data) def z_data (0...data.zsize).to_a.reverse end end #-------------------------------------------------------------------------- # * Start tone change (like in Game_screen, but for the tilemap!) #-------------------------------------------------------------------------- def start_tone_change(tone, duration) @tone_target = tone.clone @tone_duration = duration @tone = @tone_target.clone if @tone_duration == 0 end #-------------------------------------------------------------------------- # * change_tile #-------------------------------------------------------------------------- def change_tile(x,y,i,new_tile) return if data[x,y,i] == new_tile data[x,y,i] = new_tile @need_redraw = true end #-------------------------------------------------------------------------- # * Alias update (executes tone change) #-------------------------------------------------------------------------- def update if @tone_duration && @tone_duration >= 1 d = @tone_duration @tone.red = (@tone.red * (d - 1) + @tone_target.red) / d @tone.green = (@tone.green * (d - 1) + @tone_target.green) / d @tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d @tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d @tone_duration -= 1 end upd_later if @need_redraw && $scene.is_a?(Scene_Map) sort $scene.redraw_tilemap @need_redraw = false end end end #============================================================================== # ** Scene_Map EDIT #------------------------------------------------------------------------------ # Overwrites the main method in order to save the spriteset when changing # scene. #============================================================================== class Scene_Map #-------------------------------------------------------------------------- # * Constant #-------------------------------------------------------------------------- @@sdk_main_dispose = method_defined?(:main_dispose) #-------------------------------------------------------------------------- # * Main overwrite (sets the store-tileset-flag in case of scene change) #-------------------------------------------------------------------------- alias kings_tilemap_main main def main return kings_tilemap_main if @@sdk_main_dispose @spriteset = Spriteset_Map.new @message_window = Window_Message.new Graphics.transition [Graphics,Input,self].each {|s| s.update } while $scene == self Graphics.freeze $game_temp.store_tilemap = true # Set store tilemap flag to true @spriteset.dispose @message_window.dispose if $scene.is_a?(Scene_Title) Graphics.transition Graphics.freeze end end #-------------------------------------------------------------------------- # * main_dispose (if main_dispose exist) #-------------------------------------------------------------------------- if @@sdk_main_dispose alias kings_tilemap_main_dispose main_dispose def main_dispose $game_temp.store_tilemap = true kings_tilemap_main_dispose end end #-------------------------------------------------------------------------- # * Alias transfer_player (required for flawless teleport to the current map) #-------------------------------------------------------------------------- alias transfer_later transfer_player def transfer_player # If old and new_map are the same if $game_map.map_id == $game_temp.player_new_map_id $game_temp.store_tilemap = true # Set store tilemap flag end transfer_later @spriteset.tilemap.refresh # Refresh tilemap end #-------------------------------------------------------------------------- # * redraw_tilemap #-------------------------------------------------------------------------- def redraw_tilemap @spriteset.redraw_tilemap end end #============================================================================== # ** Graphics #------------------------------------------------------------------------------ # This module handles all Graphics #============================================================================== module Graphics #-------------------------------------------------------------------------- # ● class << self #-------------------------------------------------------------------------- class << self #-------------------------------------------------------------------------- # ● Alias Method #-------------------------------------------------------------------------- unless self.method_defined?(:atilemap_update) alias_method(:atilemap_update, :update) #------------------------------------------------------------------------- # ● Update #------------------------------------------------------------------------- def update atilemap_update scene = $scene return if scene.nil? || scene.is_a?(Scene_Map) spriteset = scene.instance_variables.any? {|var| scene.instance_variable_get(var).is_a?(Spriteset_Map)} $game_temp.instance_variable_set(:@store_tilemap,true) if spriteset end end end end end