Skip to content

Instantly share code, notes, and snippets.

@Arahnoid
Forked from phalkunz/ps-rotating-sprite.js
Created November 5, 2015 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arahnoid/0a2837dd5a7d28864e6d to your computer and use it in GitHub Desktop.
Save Arahnoid/0a2837dd5a7d28864e6d to your computer and use it in GitHub Desktop.
Photoshop script for preparing a sprite for rotating animation
/**
* Photoshop script for preparing a sprite for rotating animation.
* Input : a starting sprite and number of frames
* Output: the specified number of layers ready to be used in the PS animation tool
*/
var docRef = app.activeDocument;
var activeLayer = docRef.activeLayer;
var degToRotate = null;
var newLayer = null;
var secondLayer = null;
// Number of frame in total, including the original one
var numFrames = prompt('How many frames, including the original frame(layer)?', 36);
var degEachFrame = 360 / numFrames; // In degree
for(var i=0; i < numFrames - 1 ; i++) {
degToRotate = degEachFrame * (i + 1);
newLayer = activeLayer.duplicate();
newLayer.rotate(degToRotate);
newLayer.visible = false;
if(!secondLayer) secondLayer = newLayer;
}
// Move the original layer to the top sprite
activeLayer.move(secondLayer, ElementPlacement.PLACEBEFORE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment