Editing
Export Aseprite Tilemap
From F256 Foenix
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===== This LUA script file needs to be placed in Aseprite's "scripts" folder. ===== -- export tilemap.lua -- Copyright (C) 2022 Daniel Tremblay -- -- This file is released under the terms of the MIT license. local spr = app.activeSprite local pc = app.pixelColor if not spr then return print "No active sprite" end if ColorMode.TILEMAP == nil then ColorMode.TILEMAP = 4 end assert(ColorMode.TILEMAP == 4) local output_folder = app.fs.filePath(spr.filename) local function write_foenix_data(filename, data) local file = io.open(filename, "wb") local str = string.char(table.unpack(data)) file:write(str) file:close() end local function export_cel(cel) local t = { frame=cel.frameNumber-1, bounds={ x=cel.bounds.x, y=cel.bounds.y, width=cel.bounds.width, height=cel.bounds.height } } if cel.image.colorMode == ColorMode.TILEMAP then local tilemap = cel.image -- save tilemap t.tilemap = { width=tilemap.width, height=tilemap.height, tiles={} } for it in tilemap:pixels() do table.insert(t.tilemap.tiles, pc.tileI(it())) end else -- save regular cel image_n = image_n + 1 local imageFn = fs.joinPath(output_folder, "image" .. image_n .. ".png") cel.image:saveAs(imageFn) t.image = imageFn end fill_user_data(t, cel) return t end ---------------------------------------------------------------------- -- Creates output folder -- fs.makeDirectory(output_folder) -- don't!! ---------------------------------------------------------------------- -- Write /sprite.json file in the output folder local tilemapFile = app.fs.joinPath(output_folder, "tilemap.tlm") local data = {} -- add a tile because Vicky II requires it table.insert(data,0) table.insert(data,0) -- iterate over each layer for _,layer in ipairs(spr.layers) do -- iterate over each cel for _,cel in ipairs(layer.cels) do local tilemap = cel.image for it in tilemap:pixels() do table.insert(data, pc.tileI(it())) table.insert(data, 0) end end --data[y*grid.width*2 + x*2]=grid.tileIndex end --for i=1,1000 do data[i] = math.random(0,255) end write_foenix_data(tilemapFile, data)
Summary:
Please note that all contributions to F256 Foenix are considered to be released under the Creative Commons Zero (Public Domain) (see
F256 Foenix:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Page actions
Page
Discussion
Read
Edit
Edit source
History
Page actions
Page
Discussion
More
Tools
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Search
Tools
What links here
Related changes
Special pages
Page information