This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

TileConverter: Turn bitmaps into meta-tile data of any size

TileConverter: Turn bitmaps into meta-tile data of any size
by on (#60070)
So I finally got sick of converting bitmaps with a pen and paper and wrote a script to do it for me.

This script takes a bitmap, splits it down into whatever size meta-tiles you want, then outputs it into tile data you can include straight into your source code.

It'll work with any size tiles you specify, the default is 16x16 but you can do 8x8, 16x16, 32x8, it'll even do 10x93 if you want it to. Just make sure your image is actually divisible by the tile size. If you split a 100x100 px image into 8x8 tiles, you'll get weird results.

As always, I don't presume this is the best method of producing these results. This script is linux only and requires imagemagick to be installed. You can probably get it to run under cygwin, but you're on your own for that.

I've included sample input and output if you want to try it out: http://cinematicbazaar.com/?p=111

There is one limitation to the script. If a meta-tile is only used once in the original bitmap, it won't be included in the data file. This was intentional to keep the script from counting the original bitmap as a tile itself. So make sure each tile is used at least twice and you'll be fine.

I'm going to drag linux kicking and screaming into NES development one way or the other... even if I do have to write all my own tools.

by on (#60075)
Ohm,Windows could use it?it's for Linux only.

by on (#60076)
yeah,maybe at VRT Technology Co.,Ltd homepage,url]http://www.vrt.com.tw/[/url]you could download a nes tile converter ,with compressed tiles used for VT03(NES clone and add 64 colors),but it also can conver 16 colors for nes pal format.

by on (#60080)
I took a look at the script... wow. Um, I'm not sure if you realise the implications of using "eval" on all of your execution statements. Yeesh.

by on (#60081)
The eval statements are leftovers from the command line options i took out. I'm not aware of any differences between an eval and a straight up command passed to the shell when a variable wasn't in play.

by on (#60098)
Sounds like a decent setup. Is there a good way to edit the screen like that? I imagine there must be some decent tilemap-style editors out there that can output as an image, but I really have no idea.

by on (#60101)
It'll take any non-lossy image file as input, so you can use damn near anything to create the original image. I just happen to use bitmaps for my images.

The artist i'm working with uses photoshop to create the original background design, i use GIMP to edit them. He gives me images that look like this: http://cinematicbazaar.com/images/BioFo ... Level1.bmp

then i convert them into data. The next step will be to add in a hybrid RLE compression so the script's output will be exactly the same as my engine's input.

by on (#60107)
Yeah anything would work, but I tried a google search and it turned up some programs that maybe could make it easier.

I haven't used photoshop, and gimp just a little bit, so maybe it's easier than I think, but it seems like placing tiles in a normal kind of pixel-based editor would have potential for off-by-one errors all over the place. Also seems like it would be a pain to change the character set used (as displayed in the editor), that's something that's useful to do.

by on (#60108)
The idea is interesting but the chance of error are high like Memblers is pointing out. A meta-tiled map editor is what would save time for your artist but from experience.. It's a pain to make one that can be generic.

by on (#60111)
I'm sure there are better ways to generate the background composites, but my artist does a kick ass job and I'm not going to ask him to change how he operates. He can draw images using a hex editor for all i care, as long as he keeps making awesome art.

I just needed a tool to take the files he gives me and turn them into data files.

I haven't really run into off-by-one errors working on the files. Turning on a grid and "snap-to-grid" keep most things in line. Basically the process we use is to design the 16x16 meta-tiles, then just copy+paste them into place to assemble the background. The system works pretty well for us, but it may not be for everyone.

by on (#60118)
To each his own way that works, nothing wrong with that ;) With my editor, I was importing chr files. From that, I could create meta tiles. From the meta tile, I created meta-meta tile. Then with the result I could draw maps. Once all meta-tiles are defined, drawing/prototyping was quite fast. Then once the map was over, I export the data in the format I needed.

by on (#60150)
I find actually making the bitmaps to be more challenging than entering in the data by hand. But of course, entering the data by hand sucks. That's why I meet half way and make an editor where I can just drop in tiles where I please.

by on (#60159)
You are a hero! :D
Here is a tiny contribution, imagemagick can properly pad 0
http://www.imagemagick.org/Usage/files/#write_seq
Code:
# use imagemagick to crop the background into 240 16x16 tiles
convert $1 -crop $TILES output-%03d.bmp

The output will be output-001.bmp output-002.bmp ... output-093.bmp ... output-230.bmp ...

If you need more digits bump %03d to %04d

I tested it (of course removing the 2 for loops that were padding 0), same output of leveldata.

P.S. Zip file for distribution, let's see some tar.gz! ;)

by on (#60161)
Banshaku wrote:
The idea is interesting but the chance of error are high like Memblers is pointing out. A meta-tiled map editor is what would save time for your artist but from experience.. It's a pain to make one that can be generic.

Ahhh, so that's what were discussing here. Years and years back when I was trying to make a game I had to write this kind of thing, because I ran into the same issue. It sucked to have to spend so much time on a support tool.

by on (#60171)
ProgrammingAce wrote:
Turning on a grid and "snap-to-grid" keep most things in line.

That's what I do when editing level maps using GIMP. You can set the grid size to whatever your (meta)tiles' dimensions are.

by on (#60188)
How do you go about adding additional properties to tiles in your maps after generating meta tile data in this way? I know in my case it was worth the extra time to write a graphical editor for this purpose. Hopefully I'll end up making more than one game for the NES and I'll never have to write another editor, just additional map compressor plugins.

by on (#60189)
Gradualore wrote:
How do you go about adding additional properties to tiles in your maps after generating meta tile data in this way? I know in my case it was worth the extra time to write a graphical editor for this purpose. Hopefully I'll end up making more than one game for the NES and I'll never have to write another editor, just additional map compressor plugins.


I suppose you could first define all the possible metatiles, say 64 max for 16x16. Then define all the special objects as metatiles. This assumes converter doesn't need to care about the PPU's maximum. So if you defined 64 additional 'special' metatiles, then you have 6 more bits of data to convert and put in a another table for your program to interpret.

So you'd end up with a BMP file of all your graphics, and all the special objects in the game. That would be followed by the map. Since the CPU needs to know what's going on, it maybe best that the converter be able to use fixed locations when creating the metatile data.

I'm not sure if that's as workable as just having a separate layer for special objects, but i guess it could work OK. When it's all on the same layer, seems like it can be a little ambiguous.

by on (#60210)
I actually have what you would consider "special tiles" for the background knocked down to about 5 bytes per screen, so they just get stored on their own.

So i have a newer version of this script that's implemented RLE compression and outputs the tiles as letters instead of numbers. The code isn't very pretty though, so i'm not going to post it right now unless someone wants to use it right away. Once i get some free time i'll comment the code and clean it up.

The reason the new script outputs letters instead of numbers is so it's easier to do a find/replace to swap out meta-tiles. I'm using a hybrid RLE, so it looks like this "flag, tile, #repeated". If you go through and replace the output for "1" with "3", then go through on the next pass and replace tile "3" for tile "7" you're going to catch all of the "repeat 3 times" values too. By making the tiles letters, you can just do a find/replace on the letter for the tile number and don't have to worry about catching the RLE values by mistake.