Log In  

Just thought I'd throw this on the BBS in case it'd be of any use to anyone. Sorry if this is the wrong category, I wasn't too sure on where to put it.

Cart #spaz48_tiledconvert-0 | 2020-02-03 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Since the Tiled to Pico-8 map converter by @sta64 was taken down and is seemingly lost, I threw together my own. I'm sure it's a lot less nice than his was, plus this only imports and can't export, and it also can't support a full 128x64 map because of the token limit, and it's really barebones all around, but it works, and hey, that's good enough for me.

The default is 31 wide and 16 tall, and is 1-based. It's just a simple little map with the Jelpi tileset I threw together as an example. Anyway, here's how to use the thing. I highly recommend an external text editor.

First off, export your tileset to .png in Pico-8 by typing "export tileset.png" or whatever else you want to name it so long as it ends in ".png". Next, open up Tiled and create a new tileset, and open the file you exported. Set the tile width and height to 8, leave everything default, then name it and save it somewhere.

Then create a new map in Tiled, set it to whatever size you want, though note that there isn't enough tokens to fit a 128x64 table into a Pico-8 cart, so you'll either have to settle for something around 128x60 or 122x64, or make the full map and fill in the rest of the tiles yourself. If I make a second version of this, I'll definitely try and find some way to get around that, but for the time being it's good enough for me, so sorry.

Once you're done making your map, in Tiled click File > Export As... then select "Lua files (*.lua)" in the dropdown menu, and save it somewhere. Then open it up in a text editor, and scroll down until you see a table that looks somewhat like this:

data = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 35, 33, 33, 33, 33, 34, 1, 1, 1, 1, 1, 8, 9, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1,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3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0 }

Copy that whole thing, then open tiledconvert.p8.png in Pico-8, and you can either save it as a regular .p8 and open it in a text editor, or just open the code editor in Pico-8 and do things that way. Then find the "data" table in the tiledconvert cart and replace it with the one from the Lua file you made in Tiled. Then run the program, type in the width and height of the map in tiles, when it asks, and press Z to confirm. If you didn't modify the tileset png, it should be 1 based. Then, to import the map into another cart, load up that cartridge, move the tiledexport.p8 to the same folder, and in the terminal, to copy just the top 128x32 of the map enter

reload(0x2000, 0x2000, 0x1000, "tiledexport.p8")

then

cstore(0x2000, 0x2000, 0x1000)

Or to copy the whole 128x64 map (which will overwrite the bottom half of your spritesheet) enter

reload(0x1000, 0x1000, 0x2000, "tiledexport.p8")

then

cstore(0x1000, 0x1000, 0x2000)

And there you go, you should be set. I know it's a bit of a process but hopefully someone finds it useful. I figured it was better than nothing, at least. Feel free to use this however you want, no credit is necessary.

P#72657 2020-02-03 15:24

:: dw817

I'm not really understanding what you're doing here, @Spaz48. But if I did I might be able to write a tool for it in Blitz as I have a few other Pico-8 tools in the past.

https://www.lexaloffle.com/bbs/?tid=36693

https://www.lexaloffle.com/bbs/?tid=36524

P#72664 2020-02-03 18:06
:: Spaz48

@dw817 Yeah, it's a really clunky solution, really just written for my own sake but I decided to drop it on here. It's genuinely pretty simple, just kind of a pain to only do in Pico-8, and I'm not good with anything else that'd be able to do this.

Just for clarity's sake, this is Tiled: https://www.mapeditor.org/ It's an open source map editor. It saves maps as .tmx files, which from what I can tell are basically just xml files with some info and a big table. Realistically, I'm pretty sure you could cut out all of this complicated nonsense and just convert all of the values to hex, remove the commas, fill in the rest of the space with 00's, add a __map__ on top of it, then save to a .p8.

Also, the whole 1-based or 0-based thing is because i've noticed that tiled will mark the first tile as id 0 if it's totally transparent, and 1 if not, so all that does is subtract 1 from each value if you enter 1.

Honestly, It probably would've been better to ask someone else in the first place, but I'm socially awkward and not really the type to go out and ask something like that. Also sorry if I ramble, I kinda talk too much, heh.

P#72675 2020-02-03 21:01
:: dw817

Should be possible to write a Pico-8 Map Editor in Blitz.

Make up for some of the differences in @zep's editor, add grid if nothing else. Read from and save back to .P8 file.

Yeah alright. I can do this. Let me have it ready for you by Wednesday evening latest.

P#72682 2020-02-03 21:19
:: Spaz48

Wow, really? Awesome! Wasn't expecting you to make a whole map editor, but I'm sure other people would appreciate it too! By all means though, feel free to take your time. Also, a feature I'd like to request, an easy way to replace every instance of a tile with a different tile. I tend to reorganize my spritesheets and it's always a pain to go through and fix the map afterwards. Seriously though, thank you!

P#72687 2020-02-03 21:39
:: dw817

Had to check, @Spaz48. Right. This ability already exists in current mapper.

In the map editor with the pencil icon highlighted, move the cursor until it is atop the tile you want to globally change. Then pick the new tile you want to change it to from the selection below.

Hold down the CTRL key, click on that one tile. Globally change all tiles in that map to this new tile.

Press CTRL-Z to undo.

You can globally change the color of any sprite this way too with the CTRL key.

But no the editor I'm working on will be strong on the keyboard. Apparently you can't use arrow keys in P8's own map editor to move around, mine will, with grid.

P#72689 2020-02-03 21:51 ( Edited 2020-02-03 21:52)
:: Spaz48

I did know about that, but from what I've used of it it's only the tiles that are onscreen. So it's still a bit of a pain, unless I'm doing something wrong?

P#72693 2020-02-03 22:18
:: dw817

Let me think ... bringing Pico-8 up ... Hmm ... you're partially correct.

Here, use your MOUSE WHEEL to shrink the map to its smallest, then carefully CTRL+Click on the tile you want to change. That should change the lot of it, but yes, probably not the entire map if it's really big and can't be seen entirely on the screen at one time.

P#72694 2020-02-03 22:30

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-07-12 02:51 | 0.052s | 2097k | Q:45