Helloooo readers (and fellow animators)!
After a bit of searching, we couldn't seem to find a complete way to go from a framed animation in Adobe Photoshop to an ideally packed sprite sheet. Lo and behold, the
RA Animation Exporter for Adobe Photoshop was born and we'd like to share it with the animating world.
Download it now!
From a PSD...
...to a PNG sprite sheet
Click "Read More" to learn more...
Getting it to work requires no programming experience! Many thanks go to
jugenjury on ps-scripts.com and
Mark McCoy from torquepowered.com who supplied a couple sections of code.
Before we begin:
- Make sure you download
these files, which contains: RA Animation Exporter.jsx, example.psd and exampleResult.png
- Have Photoshop CS3 or higher (it should work with CS2)
- Works with PC and Mac!
Using the Animation Tool in Photoshop:
For anyone who's never used Photoshop's animation tool, it's fairly easy to pick up. "Frames" simply alter the visibility, position and style of your layers, not its contents. If there's a layer that remains the same, you can turn its visibility on across all layers.
In terms of this script, you can have as many or as few layers per frame as you wish. Whatever appears in each frame is what will appear in the final sprite sheet. Just make sure there are no blank frames and that all layers are unlocked. I should also note that I use the framed format in Photoshop and not the timeline.
Framed Animation
Here's pretty basic video tutorial on how to get started. Once the background layer is unlocked, the animation in this video should export perfectly.
What the script does:
- Saves the .PSD in order to revert back after the sprite sheet is finished
- Creates a merged copy of each frame
- Using the width, height and number of frames it determines the most optimal size for the final sprite sheet based in powers of two.
- After resizing the canvas, it places each frame in its consecutive order starting at the top left of the canvas.
- Once the final sheet has been laid out, it runs through a process that prevents a white halo appearing on the image. If you're unfamiliar with "White Halos", you can learn more about about it
from our friends at Blurst.
- Finally it uses Photoshop's Save For Web and exports the sprite sheet as a PNG-24 onto your desktop under the same name as the .PSD.
Photoshop, javascript and you:
Working with Javascript and Photoshop actually became surprisingly easy. The two most valuable sources are the
Adobe Photoshop Scripting Guide and the Photoshop Script Listener (found on page 73 in the
Scripting Guide).
Basically the script listener will log any action taken in Photoshop into a text file on your desktop. If you look at my script, the bits of incoherent code are from the script listener. I added a comment on top of each section with what it does for easy reference.
The script that we use has a few more features catered to our own engine. Here's an example that you might find useful for adding your own functionality:
var answer = confirm("Write a text file?");
if (answer == true) {
fileOut.open = new File("~\Desktop\fileName.txt");
fileOut.open("w", "TEXT", "????");
fileOut.write("Number of Frames:" + numFrames);
}
This prompts the user with a yes or no question and writes a text file on your desktop if they say yes.
Installation:
First off, I've provided a .PSD that has a basic animation and a .PNG with what the script should output to your desktop. Once you download all three things, let's put the .JSX in the right place!
Navigate to your Adobe Photoshop directory and place the .JSX into
Adobe Photoshop CS4\Presets\Scripts
Launch Photoshop (or relaunch if it was open). Open up the example.psd I gave you; an 11 frame, bouncing ball. Run the script by going to
File » Scripts and choose
RA Animation Exporter. If for some reason it's not there, you can click
Browse instead and locate
RA Animation Exporter.jsx manually. The end result should be an image called
example.png on your desktop that looks exactly like the
exampleResult.png I provided.
Known issues:
I wrote and use it with CS4, it seems to work well with CS3 and I haven't tired it with CS2, the version Animation first appeared. If you do, let me know! Here are a few things to keep in mind:
- Make sure there are at least two frames of animation
- Make sure there are no locked layers in the .psd
- Make sure every frame has at least one layer visible
Feel free to post comments, suggestions or any changes you've made yourself!
***Updated February 4th, 2010***
v1.1
Bug Fixes:
- Fixed an issue that caused some PSDs to set all layers to 0% opacity before placing them in a sprite sheet.
New Features:
- For pixelated animations, you can now turn off the "dehalo" section by opening the script and changing:
var dehaloImage = 1;
to
var dehaloImage = 0;
***Updated March 1st, 2010***
v1.2
New Features:
- You can now have the exporter put your frames one after another in a single row.
Under the new Settings section of code in the script, change:
var sheetGrid = 1;
to
var sheetGrid = 0;
***Updated January 21st, 2011***
v1.4
This latest update comes courtesy of Will Canada from DecipherOne Productions (www.decipherone.com). It seems to address a couple errors that have been cropping up for some. Here's his comment:
Code Adjusted for personal Use by Will Canada DecipherOne Productions
(This script did not initally work for me. I re-wrote frame positioning and
added the prompt for the user to specify a frame numbers because the
frame numbers weren't being passed correctly from the document.
The code also now checks to make sure that the created sprite sheets diimensions
are in a power of 2 and limits sizes to a width and height of 4096.)
Download Will's Animation Exporter v1.5
A big thanks to Will!
*** ***
Comments
Ben Ruiz
January 19th, 2010 7:05:23 pm
This really great shit, thanks a lot guys!
Anonymous
January 23rd, 2010 2:52:32 am
This is awesome! woot woot woot woot, thanks a lot.
zeroZshadow
January 27th, 2010 11:52:46 am
I get a crash " Error 8800 Generar error, couldn't do gaussian blur because the selected area is empty"
Peter
January 28th, 2010 12:07:21 pm
Hey zeroZshadow,
I tried recreating the error myself but can't quite reproduce it. Would you mind sending a copy of the .PSD that's causing it to info@retroaffect.com? Thanks!
Rich Grillotti
February 4th, 2010 10:32:37 am
Wow, this will really be helpful. Thanks! I am running into the same gaussian blur error though..
Peter
February 4th, 2010 10:39:34 am
I'm glad you found it helpful! zeroZshadow was unable to send his PSD, do you think you could send a copy of your PSD causing the error so I can get to the bottom of it? It'd be much appreciated, thanks!
info@retroaffect.com
Peter
February 4th, 2010 2:34:34 pm
I just posted version 1.1 that should solve the Gaussian Blur error. I also included an easy way to turn off the "dehalo" feature; which you'll want to do if you're creating pixelated animations.
Let me know if you get any other errors and I'll do my best to address them!
Lena
February 27th, 2010 7:47:50 pm
Fantastic script...this will really help me produce artwork quickly for a game I'm working on.
I had one minor issue - seems to create a sprite that's about 2 tiles wider and 1 tile taller than it needs to be. PSD includes a bunch of adjustment layers...don't know if that's the cause.
Tiny request - is there a way to modify the script to make a strip instead of a grid?
Thanks again!
Peter
March 1st, 2010 8:26:43 am
Hi Lena
Thanks! I'm glad it's helping you out. I've uploaded v1.2 which includes the ability to export to a strip instead of a grid. Just change the var sheetGrid to 0, instead of 1.
As for your other issue, the sheet exports to the smallest (and most optimal) power of two possible...there's most likely a decent amount of white space due to that. Do you think that could be it?
Lena
March 2nd, 2010 12:53:08 am
Wow...thanks! works perfectly :D
I can't replicate the other issue as I've since changed the artwork, but I suspect you're right. I'm pretty sure it was an odd frame count.
Meanwhile, I have RSSed this awesome blog.
Mike
April 18th, 2010 11:31:22 pm
Peter:
You have a great blog! I tried the script with example.psd, but it appears to not work with CS2. (Pop-up says error at line 159).
Cheers and Thanks,
Mike
Anonymous
April 26th, 2010 9:15:31 am
Get an error on line 310 in CS4 when running the script
Error 8800: General photoshop error occured. This functionality may not be available in this version of photoshop.
-The command "Delete" is not currently available - Line: 310 -> executeAction(idDlt, desc8, DialogModes.No); Hopefully you can fix this :)
Peter
April 27th, 2010 10:58:26 am
Hmm, if you could send me (info@retroaffect.com) the Photoshop file that causes the error, I think I could figure it out in a jiffy. Until then, I'll try recreating it myself. Thanks!
k00k
April 28th, 2010 6:38:08 pm
awsome I will send it over your tool is a huge help man!
sabri
June 30th, 2010 4:03:09 am
This is awesome! Thanks a lot Peter.
By the way, can we decide the dimensions of the sheet somehow?
Thanks
Gillissie
June 30th, 2010 3:58:47 pm
Bummer, PS crashes when I try to use it (CS3). I don't know if it really does what I'm looking for anyway. What I really need is a script similar to "Load files into stack", except instead of a stack I want a sprite sheet with a specified number of rows and columns.
Jon
July 27th, 2010 1:37:13 am
Hi Peter,
this was exactly what I was looking for.
Only thing, I'm looking for a quick way to automate turning quadrillions of .mov files to single sprite sheets. In PS cs3 you can't import a whole folder or more than one file (open yea, import nay). Won't work with batching either. Is there something I can change in the script that will let me not just IMPORT VID FRAMES TO LAYERS but rather OPEN the .movs (or sequences, whatever) to convert them. That would make my day. My week actually, literally.
Stewart
August 28th, 2010 8:21:28 pm
:'(
Anonymous
August 28th, 2010 8:25:12 pm
LOL! My comment disappeared!
Anyways, I said something along the lines of "it doesn't work in Cs2, :cry:.
When I upgrade (soon) I'll test it out in CS3 :)
Thanks!
(by the way, my comment didn't show after I put: "
TutorialStaff
September 15th, 2010 2:44:40 pm
Simple and yet great tutorial. Than you for sharing this.
Lorenz
September 17th, 2010 3:35:01 pm
The final PNG is a lot bigger than what it should be containing some unecessary space... why is that?
Peter
September 17th, 2010 3:59:22 pm
The sprite sheet is automatically sized to the nearest power of 2 since it's a requirement for our engine (and many others). You can turn it off within the script by setting sheetGrid to zero.
meatwolf
September 21st, 2010 6:16:03 am
has anyone else tried this with cs5? i am getting:
"Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- the command "Set" is not currently available. Line 184 -> executeAction (idsetd, desc7, DialogModes.NO);"
fyi,
i am getting that error with both my own aniamtion and the example.psd animation.
this script would be perfect for my needs if you can get it working with cs5...
i would be a fan for life!
thanks
randygland
October 25th, 2010 4:30:56 pm
you saved me one almighty headache,
thank you very much!
:D
Anonymous
October 27th, 2010 10:22:03 am
@meatwolf
I'm getting something close to the error you're receiving. Mine says that Merge Layers isn't a valid command. I'm also using cs5. If this script would work in cs5 I too would be a HUGE fan for life.
Anonymous
November 5th, 2010 4:17:38 pm
I'm using cs4 and i'm getting this error when i try on the example.psd you provided in the zip:
Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
-The command "Delete" is not currently available.
Line 310:
->executeAction( idDlt, desc8, DialogModes.NO);
Thanks!
Looking forward to be using this script :D!
Anonymous
January 21st, 2011 11:05:55 am
To anyone who wasn't able to get this script working.
I was having trouble initially trying to use this script as well, using CS3. I went in and traced through the code using alerts and found out where the exceptions were being thrown, as well as corrected an issue where the number of frames were not correctly being set. This version of the script now prompts the user for an argument of how many frames as the variable wasn't properly being set using the built in frames variable.
I then modified the code to take an argument for a desired texture width and put limits on the file size to maximums of 4096X4096. It also scales everything to closest power of 2. I renamed the file to AnimationExporter v1.4, as it's not officially from the RA guys, but left all of their info in tact in the file and simply appended and commented the changes I made.
You can download the file here: http://dl.dropbox.com/u/1568091/Anima tion%20Exporter%20v1.4.rar
Follow the directions in the normal RA tut, this should work out of the box for most versions.
Thanks to RA for making the script in the first place, and opening my eyes to scripting with photoshop.
Will C
January 21st, 2011 11:12:12 am
The comment above is from me, I forgot to put my user info in there. :O
Peter
January 21st, 2011 11:14:42 am
This is great. I have to apologize to anyone getting errors; Snapshot is our top priority at the moment! So, it's awesome to hear that other people are working/fixing/adding to the existing script. Many thanks to Will and anyone else doing their part!
Will
January 21st, 2011 11:17:48 am
Err.. sorry for the tripple post, but that link isn't good for copying here's the fixed one, http://dl.dropbox.com/u/1568091/Anima tionExporter v1.4.rar
Peter
January 21st, 2011 11:49:02 am
Will's version is available for download at the bottom the the post. Thanks again for the help!
Zafio
January 23rd, 2011 9:45:05 am
Thanks for this lifesaver! You should open a Flattr account and post this and the attlas thing, so people can do more than just thank you!
Kudos! And good luck with your game, looks promising!
Zafio
January 27th, 2011 7:52:55 am
Hi, little trouble here, I guess it's my fault, but can't see where is my mistake...
I try to export 16 frames (128x128) in 512x512 and the result misses 3 frames.
There are no locked layers and each frame has a visible layer so I have no clue what is going on...
Here is the psd: http://dl.dropbox.com/u/2294713/mete. psd
Zafio
January 27th, 2011 8:04:49 am
P.S.: Misses frames 5, 10, 15... I guess the pattern should be useful to identify the problem, but I still have no clue...
Will
January 27th, 2011 7:47:31 pm
Line 532 should be if (colTemp == (idealCols))
not if(colTemp > (idealCols))
nice catch, sorry about that. I'm going to post an updated version over the weekend with a few more updates.
Will
January 28th, 2011 3:57:16 am
I sent Peter an update to the script that addresses the off screen drawing issue. Sorry to anyone who had experienced that.
kdb
January 31st, 2011 10:29:57 pm
Hi...
I am using CS3, your example.psd and Will's version 1.4. I can get it to work for the strip and that is really fantastic but when trying to make a grid it crashes with the "The canvas size must be in powers of 2. The script will now exit." message. Does anyone know how I can fix this?
PDN user
February 24th, 2011 2:12:02 pm
Paint.NET version? :D
Nyarlothep
February 25th, 2011 7:43:20 am
The strip works just fine, however even after I changed line 532 (actually 531) the grid view did not work properly on large canvases. If I specify 4096 with a 1024 x 1024 sized canvas on a 17 frame sprite animation all I get is the first 4 frames arranged on a 4096 x 1024 png . However, with a 256x256 14 frame animation the grid works when I choose 1024. I thought it was because there were too many frames for it handle but the outcome is still the same when I choose tho render 8 frames of 1024x1024 which fills a 4096x4096 canvas fully. What is causing this how can I get this to work? A quick fix is to have it render in a line and then manually arrange the sprites to fit 4096 x 4096 but it kind of defeats the purpose of the script. Any thanks will be greatly appreciated. Thanks in advance.
Will C
February 28th, 2011 12:15:52 pm
I sent peter and updated version a few weeks ago, but I know those guys are probably busy with gdc and getting ready for pax and stuff, so I don't think he ever got around to posting the updated version. You can however find version 1.5 on my site http://www.decipherone.com which address the following issues.
V1.5 by Will Canada
Adjusted logic error that was causing frames to, under certain conditions, be drawn outside of the sprite sheet.
In the previous version the script placed the last layer as the first frame, this was counter-intuitive to photoshop, script
now places first layer as first frame.
Fixed Issue where the number of rows wasn’t properly scaling beyond a certain threshold.
Corrected spelling error in a user prompt.
WillC
February 28th, 2011 12:27:47 pm
Here's the exact url for that post incase it gets knocked off the front page:
http://www.decipherone.com/ind ex.php/2011/01/willc/news/animation-e xport-update/
Victor Reano
March 1st, 2011 11:42:42 pm
This is a pretty good script, but I'm one of the many users that doesn't animate my canvas size in powers of 2. I also would like to set the number of columns to my liking.
So I couldn't find one, so I made my own, based off another person's script. This isn't completely dummy-proof, follow the same instructions as above, and make sure all your frames cells are the same width/height per frame. This takes your frames, and asks you how many columns you'd like and it generates a new PSD file as a sprite sheet in layers. Tested only in CS5. Enjoy!
http://www.snowfare.com/photo shop/generate_sprite_sheet.jsx
Ashe
March 13th, 2011 10:23:20 am
Awesome! Using it on CS5, no problems so far! Using it for pixel art on game project! Saves me a million head aches!
Hugo
March 15th, 2011 12:21:21 am
works amazingly! THANKS ALOT!
Anonymous
March 30th, 2011 7:31:24 pm
HARD ROCKIN' YAYUHHH
Yes, it works with PS CS5. Easy cheezy. Great script. A script of greatness.
Pra
April 12th, 2011 2:01:01 am
THANK YOU SOO MUCH. THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU .
Tom
April 16th, 2011 7:16:36 am
Very nice. I am writing some other pixel art plugins for photoshop too. I'd prefer using Pixen, but it's so broken.
dyego
April 18th, 2011 8:59:12 pm
it's not working well in my photoshop cs5 64 bits, the scrypt saves the image, but it was empty.
Anonymous
April 20th, 2011 8:48:18 pm
thx for the script.
Dyego did you happened to alt-tab while using the script?
Thomas Link
May 6th, 2011 2:11:27 am
Nice Script - but it does not work on a German-language Photoshop CS5.
Anyway, I would love to use it for Icon-Sprites, which are usually ordered in one dimension (vertical or horizontal) only.
Bakame!
June 14th, 2011 6:29:13 pm
Guys, it AWESOME!
I moved from flash to photoshop last projects, to make animation, your post save my life:)
CC
July 22nd, 2011 4:09:33 am
great, thanks a lot, saved me hours ;)
cheers
Max
October 8th, 2011 6:17:27 am
Just putting this here incase someone else has the same issue:
The script would continuously output an opaque square, but not my frames.
My background layer wasn't visible on any animation frame, which may have had something to do with it, because after deleting the background layer, the script output correctly.
Great script, thanks RA.
Stephen
October 12th, 2011 3:04:04 pm
Just want to say this is a great script, thanks!
HankSpoon
October 21st, 2011 5:59:40 am
Hi, downlaod link of version 1.4 is dead, can you refresh it?
Thanks a lot
Peter
October 21st, 2011 6:05:45 am
Updated! Just changed it to 1.5
xSkyChainx
November 8th, 2011 12:12:18 pm
Hi, I'm getting some errors telling me the action can't be finished 'cause the destination folder doesn't exist! I went into the code and found the place where you specify it, but it would be great if you would implement a step where you can browse to the destination folder during export! Or am I doing something wrong? ^-^
Chibi
November 16th, 2011 2:44:34 pm
Amazing, thank you!!
Anonymous
November 30th, 2011 10:29:45 am
Thank you so much. great work :)
anon
December 10th, 2011 12:13:59 am
F*** yes! Thx!
Anonymous
December 21st, 2011 8:31:48 am
thank you so much! very useful, but have a question, will it be possible to pack a non power of 2 animation? the reason for this is that you can pack one animation in one file, then pack a group of different animations into one sprite sheet which is a power of 2, but the smaller animations are not a power of 2... so that way you can pack several sprite animations into one big sprite sheet... just a though
TESTING