├── SpritePlane.jsx └── README.md /SpritePlane.jsx: -------------------------------------------------------------------------------- 1 | // Save the current preferences 2 | var startRulerUnits = app.preferences.rulerUnits; 3 | var startTypeUnits = app.preferences.typeUnits; 4 | var startDisplayDialogs = app.displayDialogs; 5 | 6 | // Set Photoshop to use pixels and display no dialogs 7 | app.preferences.rulerUnits = Units.PIXELS; 8 | app.preferences.typeUnits = TypeUnits.PIXELS; 9 | app.displayDialogs = DialogModes.NO; 10 | 11 | var layerNum = app.activeDocument.layers.length; 12 | var docWidth = app.activeDocument.width; 13 | var docHeight = app.activeDocument.height; 14 | var rows; 15 | var columns; 16 | var i = 0; // Active layer counter 17 | 18 | // layer.Translate is broken, that asshole. Here's the improvised one 19 | function translateActiveLayer( deltaX, deltaY ) 20 | { 21 | var desc = new ActionDescriptor(); 22 | var ref = new ActionReference(); 23 | ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 24 | desc.putReference( charIDToTypeID('null'), ref ); 25 | var coords = new ActionDescriptor(); 26 | coords.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), deltaX ); 27 | coords.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), deltaY ); 28 | desc.putObject( charIDToTypeID('T '), charIDToTypeID('Ofst'), coords ); 29 | executeAction( charIDToTypeID('move'), desc, DialogModes.NO ); 30 | }; 31 | 32 | var inp = confirm("Welcome to SpritePlane v1.0!\r\rSelect layout mode:\rYes - automatic mode (optimal number of rows/columns).\rNo - manual mode (user-specified number of rows/columns)."); 33 | if (inp==true) 34 | { 35 | rows = Math.round (Math.sqrt (layerNum)); 36 | columns = Math.ceil (layerNum / rows); 37 | }; 38 | 39 | else 40 | { 41 | columns = prompt ("Enter the number of columns (1 or more):","1"); 42 | rows = prompt ("Enter the number of rows ("+Math.ceil (layerNum / columns)+" or more recommended):",""+Math.ceil (layerNum / columns)+""); 43 | }; 44 | var inp = confirm("The sprite frames will be arranged in "+columns+" columns and "+rows+" rows.\rThe sprite sheet will be "+columns*docWidth+" wide and "+rows*docHeight+" tall. \r\rContinue?"); 45 | if (inp==true) 46 | { 47 | app.activeDocument.resizeCanvas(docWidth*columns, docHeight*rows, AnchorPosition.TOPLEFT); 48 | 49 | for (var rowCount = 1; rowCount<=rows; rowCount++) 50 | { 51 | for (var colCount =1; colCount<=columns; colCount++) 52 | { 53 | i++; 54 | if (layerNum >= i) 55 | { 56 | app.activeDocument.activeLayer = activeDocument.layers[layerNum-i]; 57 | translateActiveLayer(docWidth * (colCount-1), docHeight * (rowCount-1)) ; 58 | }; 59 | }; 60 | }; 61 | alert("Completed!"); 62 | }; 63 | 64 | else 65 | { 66 | alert("Cancelled!"); 67 | } 68 | 69 | // Reset the application preferences 70 | app.preferences.rulerUnits = startRulerUnits; 71 | app.preferences.typeUnits = startTypeUnits; 72 | app.displayDialogs = startDisplayDialogs; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Welcome to SpritePlane v1.0! 2 | ============================ 3 | 4 | About 5 | ----- 6 | 7 | **SpritePlane** is a sprite sheet generator script for Adobe Photoshop that relieves you from many monotonous and 8 | time-consuming tasks, such as manually dragging and aligning sprite frames, and makes the generation of sprite sheets 9 | a matter of seconds. 10 | 11 | So basically what it does is it converts ![Sprites](http://i.imgur.com/c2MEB.gif "Sprites") 12 | to ![Sprite sheets](http://i.imgur.com/FDHsu.png "Sprite sheets"). 13 | 14 | I'm an aspiring video game artist, and while working on my latest project me and my team felt the need of an automated 15 | solution to generating sprite sheets. Most of the scripts we found online were either stand-alone, with external library 16 | dependencies, or lacked the features we were looking for. And so I've decided to develop a script for Photoshop, the tool 17 | we're using in our development, and then release it to the public. I sincerely hope that our script will aid you in your 18 | development, and improve your sprite workflow. 19 | 20 | Questions? Issues? Requests? Found a bug? Just thanks? Hit me up right here in [Issues](https://github.com/mediochrea/SpritePlane/issues), 21 | by [email](mailto:mediochrea@gmail.com), or on [Polycount](http://www.polycount.com/forum/member.php?u=48535). 22 | 23 | Tested on: 24 | 25 | * Adobe Photoshop CS5 x86-32 26 | * Adobe Photoshop CS5 x86-64 27 | 28 | Features 29 | -------- 30 | 31 | * Fast, simple workflow via the automation of repetetive tasks 32 | * Two layout planning modes: automatic and manual 33 | * Support for direct Photoshop transparency 34 | 35 | Installation 36 | ------------ 37 | 38 | 1. Close Photoshop. 39 | 2. Copy the *SpritePlane.jsx* file to: 40 | * Windows: *C:\Program Files\Adobe\your_photoshop_version\Presets\Scripts* 41 | * Mac: *Applications > Your Photoshop Version > Presets > Scripts* 42 | 3. Open Photoshop. 43 | 4. The script should now be accessible from the *File > Scripts* menu. 44 | 45 | Usage 46 | ----- 47 | 48 | 1. Open your sprite in Photoshop (imported animated gifs work perfectly and without any tweaks). 49 | 2. The structure of your document must follow several guidelines: 50 | * There must be no background layer or locked layers. 51 | * The layers must be arranged in a way that the first frame of your sprite is on Layer 1, the second — on Layer 2 and so on. 52 | * Layers with applied styles, masks or adjustments must be rasterized or converted to smart objects (rasterization works best). 53 | 3. Run the script from the *File > Scripts* menu or from the actual *SpritePlane.jsx* file. 54 | 4. Follow the helpful dialogues to generate the sprite sheet. 55 | 56 | FAQ 57 | --- 58 | 59 | * Nothing here. *Yet...* 60 | 61 | Future plans 62 | ------------ 63 | 64 | * The reverse (sprite sheet to animated sprite) functionality 65 | * Less restrictions, more exceptions 66 | * Alpha channel (indirect transparency) support 67 | * Proper GUI, with a more user-friendly look 68 | * More poka-yoke 69 | * Even more useful features, like instant saving, loading multiple images etc. 70 | * Cleaner code with more comments 71 | * A web interface, maybe? 72 | 73 | Version history 74 | --------------- 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
VersionDateNotes
1.027.04.2012Initial release.
84 | 85 | License 86 | ------- 87 | 88 | Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. --------------------------------------------------------------------------------