Editing
Export Aseprite Sprites
(section)
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_sprite_256.lua <nowiki>local sprite = app.sprite -- Check constraints if sprite == nil then app.alert("No Sprite...") return end if sprite.colorMode ~= ColorMode.INDEXED then app.alert("Sprite needs to be indexed") return end local function getPaletteData(palette) local ncolors = #palette local res = string.format(";%i\n", ncolors) for i=0, ncolors-1 do local color = palette:getColor(i) res = res .. " .byte " .. string.format("$%x,$%x,$%x,$%x\n", color.blue, color.green, color.red, color.alpha) end return res end local function getIndexData(img, x, y, w, h) local res = "" for y = 0,h-1 do res = res .. " .byte " for x = 0, w-1 do if x > 0 then res = res .."," end px = img:getPixel(x, y) res = res .. string.format("$%x", px) end res = res .. "\n" end return res end local function exportFrame(frm,sFlag) if frm == nil then frm = 1 end local img = Image(sprite.spec) img:drawSprite(sprite, frm) if frm == 1 or frm == nil or sFlag == 1 then io.write(";Palette Indexed Picture\n") io.write("CLUT:\n") io.write(";begin palette\n") io.write(getPaletteData(sprite.palettes[1])) io.write(";end palette\n\n") end io.write("sprite") io.write(frm) io.write(":\n") io.write(";begin Sprite\n") io.write(getIndexData(img, x, y, sprite.width, sprite.height)) io.write(";end Sprite\n\n") end local dlg = Dialog() dlg:file{ id = "exportFile", label = "File", open = false, save = true, --filename= p .. fn .. "pip", filetypes = {"txt", "pip" }} dlg:check{ id="onlyCurrentFrame", text="Export only current frame", selected=false } dlg:modify{ title = "F256 Export Sprite" } dlg:button{ id="ok", text="OK" } dlg:button{ id="cancel", text="Cancel" } dlg:show() local data = dlg.data if data.ok then local f = io.open(data.exportFile, "w") io.output(f) if data.onlyCurrentFrame then exportFrame(app.frame.frameNumber,1) else for i = 1,#sprite.frames do exportFrame(i,0) end end io.close(f) end</nowiki>
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