Procedural Tileset and Tilemap

RPG Maker (RGSS)

Procedural Tileset and Tilemap

Let's create a cool Tilemap shuffle effect.

TILEMAP SHUFFLE EFFECT

It’s possible to create a map and its tilemap data completely by code.

1-) Open RPG Maker VX and open the Script Editor. Hotkey is F11.
2-) Delete every file-based section of code. Absolutely everything. Hotkey is Del for each entry.
3-) Create a new file. Hotkey is Ins in the file-like explorer section.
4-) Enter the following pieces of code in the editor.

### SETTINGS

screen_width = 640
screen_height = 480

tileset_width = 512
tileset_height = 512

Graphics.resize_screen(screen_width, screen_height)

tile_def = 32

rect = Rect.new(0,0,31,31)
color = Color.new(0, 0, 0)

### CREATE MAP PROCEDURALLY

@map = RPG::Map.new(screen_width/tile_def, screen_height/tile_def)
@map.display_name = "Procedural Map"
@map.tileset_id = 0

### CREATE TILESET BITMAP
### EACH TILE WITH GRADIENT INCREMENT

@bmp_tileset = Bitmap.new(tileset_width, tileset_height)

for y in 0..(tileset_width/tile_def)-1
for x in 0..(tileset_height/tile_def)-1

rect.x = x*tile_def
rect.y = y*tile_def

color.blue += 1

@bmp_tileset.fill_rect(rect, color)

end
end

### CREATE TILEMAP

@tilemap = Tilemap.new
@tilemap.map_data = @map.data
@tilemap.bitmaps[5] = @bmp_tileset

### UPDATE TILEMAP WITH RANDOM TILES

loop do

for y in 0..15
for x in 0..20
tile_id = rand(254)+1
@tilemap.map_data[x,y,0] = tile_id
end
end

Graphics.update
Graphics.wait(12)
end

What happens in this program is that we’ve created a tileset with 256 tiles, each with a different blue color gradient. Then in the main loop, we change the whole tilemap at each frame with random tile ids from 0 to 255. It produces the following result.

Leave a Reply

Your email address will not be published. Required fields are marked *