Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[VX] Information block ID tile

From

Member

How to get the bitmap variable (which contains the image) of each block of the tilesets as the block ID of the tile taken from $ game_map.data [x, y, z]?

I hope someone knows how to advise ^^
 
Man, I thought the XP tileset was goofy....

If you look at the "create_tilemap" method in Spriteset_Map, you'll see that each of the tileset images gets loaded into:
@tilemap.bitmaps[0..8]

Writing a little test routine to print the value returned in $game_map.data [x, y, z], it looks like each file contains the following tile IDs:

0 - 255: TileB
256 - 511: TileC
512 - 767: TileD
768 - 1023: TileE
1536 - ? : TileA5
2048 - 2815: TileA1
2816 - 4351: TileA2
4352 - 5887: TileA3
5888 + : TileA4

It looks like each of the animated autotiles uses 48 indexes to store all of the possible combinations of the autotile.
It stands to reason that the non-animated autotiles would use 16 indexes, but that doesn't seem like enough to me...???
I think you can extend TileE, making it twice it's original size & use the range 768 - 1535.
I didn't test where TileA5 ended, or the upper range of TileA4.
 

MarkR

Member

I made a script a while ago which draws a tile at a location:

Code:
  #--------------------------------------------------------------------------

  # * Draw tile

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

  def draw_tile(x, y, tile_id)

    # Get x and y locations of the tile_id

    sx = (tile_id / 128 % 2 * 8 + tile_id % 8) * 32

    sy = (tile_id % 256 / 8 % 16             ) * 32

    # Get tileset bitmap

    bitmap = tileset_bitmap(tile_id)

    # Stop if tile_id is out of range

    return if bitmap.nil?

    self.contents.blt(x, y, bitmap, Rect.new(sx, sy, 32, 32)) 

  end

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

  # * Get tile set image that includes the designated tile

  #     tile_id : Tile ID

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

  def tileset_bitmap(tile_id)

    set_number = tile_id / 256

    return Cache.system("TileB") if set_number == 0

    return Cache.system("TileC") if set_number == 1

    return Cache.system("TileD") if set_number == 2

    return Cache.system("TileE") if set_number == 3

    return nil

  end

It uses two methods draw_tile(x, y, tile_id) and tileset_bitmap(tile_id). The last one was copied from the Spirte_Character class.
You can use the tileset_bitmap method to get the tileset which is used by the tile id.

The draw_tile method is used to draw the tile at a specified location. You could change the method yourself so it only returns a bitmap of the tile.

The methods aren't compatible with tiles from the TileA tileset.
 

MarkR

Member

Hey, sorry for the late reply I kind of forgot about this topic. :blush:

The methods I gave you can be inserted in a Window class. If you call draw_tile(x, y, tile_id) then the method will draw the specified tile at the x, y location of the window's contents.
So the method doesn't return the bitmap value, but draws a small part (a 32 x 32 square / tile) of the tileset. If you want to get the bitmap of the tile then you can use the following code:
Code:
  #--------------------------------------------------------------------------

  # * Tile bitmap

  # Returns the bitmap corresponding with the specified tile_id

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

  def tile_bitmap(tile_id)

    bitmap = Bitmap.new(32, 32)

    # Get x and y locations of the tile_id

    sx = (tile_id / 128 % 2 * 8 + tile_id % 8) * 32

    sy = (tile_id % 256 / 8 % 16             ) * 32

    # Get tileset bitmap

    tileset_bitmap = tileset_bitmap(tile_id)

    # Stop if tile_id is out of range

    return if tileset_bitmap.nil?

    # Draw tile on the bitmap and return it

    return bitmap.blt(x, y, bitmap, Rect.new(sx, sy, 32, 32))

  end

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

  # * Get tile set image that includes the designated tile

  #     tile_id : Tile ID

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

  def tileset_bitmap(tile_id)

    set_number = tile_id / 256

    return Cache.system("TileB") if set_number == 0

    return Cache.system("TileC") if set_number == 1

    return Cache.system("TileD") if set_number == 2

    return Cache.system("TileE") if set_number == 3

    return nil

  end

You can insert the methos in a class in which you want to use the methods.
 

MarkR

Member

From":3aexdyy6 said:
Can you by chance give me a demo example? Please?

Yeah sure, but what kind of demo would you like? I could make a window which shows the tile which the player is standing on.

Edit: Here is a script that creates a window which shows the tiles the player is standing on. It doesn't show the tiles from tileset A1-A4 as I'm not sure how to create those tiles.. :(

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

# ** Window_Tile_Info

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

#  Show the tiles the player is standing on (excluding tiles from tileset A1 - A4)

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

class Window_Tile_Info < Window_Base

  def initialize

    super(0, 0, 34 * 4, 96)

    # Make window transparant

    self.opacity = 150

    # Refresh window's content

    refresh

  end

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

  # * Refresh

  # Show the tiles the player is standing on (excluding tiles from tileset A1 - A4)

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

  def refresh

    self.contents.clear

    # Remember the player's location

    @player_x, @player_y = $game_player.x, $game_player.y   

    # Draw the tiles the player is standing on

    for z in 0..2 

      tile_id = $game_map.data[@player_x, @player_y, z]

      # Draw tile image on the window

      draw_tile(z * 34, 0, tile_id)    

    end

  end

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

  # * Update

  # Refresh if the player has moved

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

  def update

    refresh unless @player_x == $game_player.x and @player_y == $game_player.y

  end

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

  # * Draw tile

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

  def draw_tile(x, y, tile_id)

    # Get tileset bitmap

    bitmap = tileset_bitmap(tile_id)

    # Stop if tile_id is out of range

    return if bitmap.nil? or tile_id / 256 >= 8

    # Get x and y locations of the tile_id

    sx = (tile_id / 128 % 2 * 8 + tile_id % 8) * 32

    sy = (tile_id % 256 / 8 % 16             ) * 32

    self.contents.blt(x, y, bitmap, Rect.new(sx, sy, 32, 32))

  end

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

  # * Get tile set image that includes the designated tile

  #     tile_id : Tile ID

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

  def tileset_bitmap(tile_id)

    set_number = tile_id / 256

    return Cache.system("TileB")  if set_number == 0

    return Cache.system("TileC")  if set_number == 1

    return Cache.system("TileD")  if set_number == 2

    return Cache.system("TileE")  if set_number == 3    

    return Cache.system("TileA5") if set_number >= 6  and set_number < 8

    return nil

  end

  

end

 

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

# ** Scene_Map

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

#  Create, update and dispose the tile info window

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

class Scene_Map

  alias start_tile_info start unless $@

  def start

    start_tile_info

    @tile_info_window = Window_Tile_Info.new

  end

  

  alias update_tile_info update unless $@

  def update

    @tile_info_window.update

    update_tile_info

  end

  

  alias terminate_tile_info terminate unless $@

  def terminate

    @tile_info_window.dispose

    terminate_tile_info

  end

  

end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top