Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started adding support for generating sprite sheets

  • Loading branch information...
commit 7fe0c3beb3fdd6cdf508848d0f8d3ec809cfe119 1 parent 318b00d
Viktor Lidholt authored
View
4 CocosBuilder/CocosBuilder.xcodeproj/project.pbxproj
@@ -354,6 +354,7 @@
E385A41E14F6993E00DFB12D /* CCBPMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = E385A41D14F6993E00DFB12D /* CCBPMenu.m */; };
E385A42014F69FF300DFB12D /* InspectorBlock.xib in Resources */ = {isa = PBXBuildFile; fileRef = E385A41F14F69FF300DFB12D /* InspectorBlock.xib */; };
E385A42314F6A01900DFB12D /* InspectorBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = E385A42214F6A01900DFB12D /* InspectorBlock.m */; };
+ E38DAB22165AC18800EA24E4 /* reshandler-spritesheet-folder.png in Resources */ = {isa = PBXBuildFile; fileRef = E38DAB21165AC18800EA24E4 /* reshandler-spritesheet-folder.png */; };
E3926188159C69D20034FF1D /* SequencerKeyframeEasing.m in Sources */ = {isa = PBXBuildFile; fileRef = E3926187159C69D20034FF1D /* SequencerKeyframeEasing.m */; };
E392618F159CAAA10034FF1D /* seq-keyframe-interpol-vis.png in Resources */ = {isa = PBXBuildFile; fileRef = E392618A159CAAA10034FF1D /* seq-keyframe-interpol-vis.png */; };
E3926190159CAAA10034FF1D /* seq-keyframe-l-sel.png in Resources */ = {isa = PBXBuildFile; fileRef = E392618B159CAAA10034FF1D /* seq-keyframe-l-sel.png */; };
@@ -1346,6 +1347,7 @@
E385A41F14F69FF300DFB12D /* InspectorBlock.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = InspectorBlock.xib; sourceTree = "<group>"; };
E385A42114F6A01900DFB12D /* InspectorBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorBlock.h; sourceTree = "<group>"; };
E385A42214F6A01900DFB12D /* InspectorBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InspectorBlock.m; sourceTree = "<group>"; };
+ E38DAB21165AC18800EA24E4 /* reshandler-spritesheet-folder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "reshandler-spritesheet-folder.png"; sourceTree = "<group>"; };
E3926186159C69D20034FF1D /* SequencerKeyframeEasing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SequencerKeyframeEasing.h; sourceTree = "<group>"; };
E3926187159C69D20034FF1D /* SequencerKeyframeEasing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SequencerKeyframeEasing.m; sourceTree = "<group>"; };
E392618A159CAAA10034FF1D /* seq-keyframe-interpol-vis.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "seq-keyframe-interpol-vis.png"; sourceTree = "<group>"; };
@@ -2032,6 +2034,7 @@
776041F01498FD630078095D /* GUI */ = {
isa = PBXGroup;
children = (
+ E38DAB21165AC18800EA24E4 /* reshandler-spritesheet-folder.png */,
5811305F1639C52000A86D70 /* seq-startmarker.png */,
E367E32416384F3600247F12 /* orientation-portrait.png */,
E367E31C16384F0C00247F12 /* orientation-landscapeleft.png */,
@@ -4127,6 +4130,7 @@
E367E32516384F3600247F12 /* orientation-portrait.png in Resources */,
581130601639C52500A86D70 /* seq-startmarker.png in Resources */,
E3808DB41641C45B00398456 /* PublishSettingsWindow.xib in Resources */,
+ E38DAB22165AC18800EA24E4 /* reshandler-spritesheet-folder.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN  CocosBuilder/Resources/reshandler-spritesheet-folder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
56 CocosBuilder/ccBuilder/CCBPublisher.m
@@ -35,6 +35,7 @@
#import "PlayerDeviceInfo.h"
#import "ResourceManager.h"
#import "CCBFileUtil.h"
+#import "Tupac.h"
@implementation CCBPublisher
@@ -177,6 +178,8 @@ - (BOOL) copyFileIfChanged:(NSString*)srcFile to:(NSString*)dstFile forResolutio
- (BOOL) publishDirectory:(NSString*) dir subPath:(NSString*) subPath
{
+ NSLog(@"publishDirectory: %@ subPath: %@", dir, subPath);
+
CocosBuilderAppDelegate* ad = [CocosBuilderAppDelegate appDelegate];
ResourceManager* resManager = [ResourceManager sharedManager];
NSArray* resIndependentDirs = [resManager resIndependentDirs];
@@ -224,6 +227,18 @@ - (BOOL) publishDirectory:(NSString*) dir subPath:(NSString*) subPath
[files addObjectsFromArray:[fm contentsOfDirectoryAtPath:autoDir error:NULL]];
}
+ // Check for generated sprite sheets
+ BOOL isGeneratedSpriteSheet = NO;
+ NSString* spriteSheetDefFile = [dir stringByAppendingPathExtension:@"ccbSpriteSheet"];
+ if ([fm fileExistsAtPath:spriteSheetDefFile])
+ {
+ isGeneratedSpriteSheet = YES;
+
+ // Clear temporary sprite sheet directory
+ [fm removeItemAtPath:[projectSettings tempSpriteSheetCacheDirectory] error:NULL];
+ }
+
+ // Iterate through all files
for (NSString* fileName in files)
{
if ([fileName hasPrefix:@"."]) continue;
@@ -241,6 +256,9 @@ - (BOOL) publishDirectory:(NSString*) dir subPath:(NSString*) subPath
// Skip resource independent directories
if ([resIndependentDirs containsObject:fileName]) continue;
+ // Skip generated sprite sheets
+ if (isGeneratedSpriteSheet) continue;
+
[self publishDirectory:filePath subPath:childPath];
}
else
@@ -250,11 +268,22 @@ - (BOOL) publishDirectory:(NSString*) dir subPath:(NSString*) subPath
// Copy files
for (NSString* ext in copyExtensions)
{
+ // Skip non png files for generated sprite sheets
+ if (isGeneratedSpriteSheet && ![ext isEqualToString:@"png"]) continue;
+
if ([[fileName lowercaseString] hasSuffix:ext] && !projectSettings.onlyPublishCCBs)
{
// This file should be copied
NSString* dstFile = [outDir stringByAppendingPathComponent:fileName];
+ // Use temp cache directory for generated sprite sheets
+ if (isGeneratedSpriteSheet)
+ {
+ dstFile = [[projectSettings tempSpriteSheetCacheDirectory] stringByAppendingPathComponent:fileName];
+
+ NSLog(@"dstFile: %@", dstFile);
+ }
+
if (![self copyFileIfChanged:filePath to:dstFile forResolution:NULL]) return NO;
if (publishForResolutions)
@@ -268,7 +297,7 @@ - (BOOL) publishDirectory:(NSString*) dir subPath:(NSString*) subPath
}
// Publish ccb files
- if ([[fileName lowercaseString] hasSuffix:@"ccb"])
+ if ([[fileName lowercaseString] hasSuffix:@"ccb"] && !isGeneratedSpriteSheet)
{
NSString* strippedFileName = [fileName stringByDeletingPathExtension];
@@ -295,6 +324,31 @@ - (BOOL) publishDirectory:(NSString*) dir subPath:(NSString*) subPath
}
}
+ if (isGeneratedSpriteSheet)
+ {
+ // Sprite files should have been saved to the temp cache directory, now actually generate the sprite sheets
+ NSString* spriteSheetDir = [outDir stringByDeletingLastPathComponent];
+ NSString* spriteSheetName = [outDir lastPathComponent];
+
+ for (NSString* res in publishForResolutions)
+ {
+ NSArray* srcDirs = [NSArray arrayWithObjects:
+ [projectSettings.tempSpriteSheetCacheDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"resources-%@", res]],
+ projectSettings.tempSpriteSheetCacheDirectory,
+ nil];
+
+ NSString* spriteSheetFile = NULL;
+ if (publishToSingleResolution) spriteSheetFile = outDir;
+ else spriteSheetFile = [[spriteSheetDir stringByAppendingPathComponent:[NSString stringWithFormat:@"resources-%@", res]] stringByAppendingPathComponent:spriteSheetName];
+
+ NSLog(@"SPRITE SHEET src: %@ out: %@", srcDirs, spriteSheetFile);
+ Tupac* packer = [Tupac tupac];
+ packer.outputName = spriteSheetFile;
+ packer.outputFormat = TupacOutputFormatCocos2D;
+ [packer createTextureAtlasFromDirectoryPaths:srcDirs];
+ }
+ }
+
return YES;
}
View
1  CocosBuilder/ccBuilder/ProjectSettings.h
@@ -104,6 +104,7 @@
@property (nonatomic, retain) NSMutableArray* availableExporters;
@property (nonatomic, readonly) NSString* displayCacheDirectory;
@property (nonatomic, readonly) NSString* publishCacheDirectory;
+@property (nonatomic, readonly) NSString* tempSpriteSheetCacheDirectory;
@property (nonatomic, assign) BOOL deviceOrientationPortrait;
@property (nonatomic, assign) BOOL deviceOrientationUpsideDown;
@property (nonatomic, assign) BOOL deviceOrientationLandscapeLeft;
View
6 CocosBuilder/ccBuilder/ProjectSettings.m
@@ -284,6 +284,12 @@ - (NSString*) publishCacheDirectory
return [[[[paths objectAtIndex:0] stringByAppendingPathComponent:@"com.cocosbuilder.CocosBuilder"] stringByAppendingPathComponent:@"publish"]stringByAppendingPathComponent:self.projectPathHashed];
}
+- (NSString*) tempSpriteSheetCacheDirectory
+{
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+ return [[[paths objectAtIndex:0] stringByAppendingPathComponent:@"com.cocosbuilder.CocosBuilder"] stringByAppendingPathComponent:@"spritesheet"];
+}
+
- (BOOL) store
{
return [[self serialize] writeToFile:self.projectPath atomically:YES];
View
6 CocosBuilder/ccBuilder/ResourceManager.h
@@ -39,7 +39,8 @@ enum
kCCBResTypeTTF,
kCCBResTypeCCBFile,
kCCBResTypeJS,
- kCCBResTypeAudio
+ kCCBResTypeAudio,
+ kCCBResTypeGeneratedSpriteSheetDef,
};
@@ -88,6 +89,7 @@ enum
int count;
NSString* dirPath;
NSMutableDictionary* resources;
+ BOOL isDynamicSpriteSheet;
NSMutableArray* any;
NSMutableArray* images;
@@ -101,6 +103,8 @@ enum
@property (nonatomic,assign) int count;
@property (nonatomic,retain) NSString* dirPath;
@property (nonatomic,readonly) NSMutableDictionary* resources;
+@property (nonatomic,assign) BOOL isDynamicSpriteSheet;
+
@property (nonatomic,readonly) NSMutableArray* any;
@property (nonatomic,readonly) NSMutableArray* images;
@property (nonatomic,readonly) NSMutableArray* animations;
View
74 CocosBuilder/ccBuilder/ResourceManager.m
@@ -159,6 +159,8 @@ - (void) dealloc
@implementation RMDirectory
+@synthesize isDynamicSpriteSheet;
+
@synthesize count;
@synthesize dirPath;
@synthesize resources;
@@ -199,6 +201,35 @@ - (NSArray*)resourcesForType:(int)type
return NULL;
}
+- (void) updateIsDynamicSpriteSheet
+{
+ if (dirPath)
+ {
+ NSLog(@"updateIsDynamicSpriteSheet dirPath: %@", dirPath);
+
+ NSString* dirSettingsPath = [dirPath stringByAppendingPathExtension:@"ccbSpriteSheet"];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:dirSettingsPath])
+ {
+ self.isDynamicSpriteSheet = YES;
+ }
+ else
+ {
+ self.isDynamicSpriteSheet = NO;
+ }
+ }
+}
+
+- (void) setDirPath:(NSString *)dp
+{
+ if (dp != dirPath)
+ {
+ [dirPath release];
+ dirPath = [dp retain];
+ }
+
+ [self updateIsDynamicSpriteSheet];
+}
+
- (void) dealloc
{
[resources release];
@@ -420,6 +451,10 @@ - (int) getResourceTypeForFile:(NSString*) file
{
return kCCBResTypeAudio;
}
+ else if ([ext isEqualToString:@"ccbspritesheet"])
+ {
+ return kCCBResTypeGeneratedSpriteSheetDef;
+ }
return kCCBResTypeNone;
}
@@ -477,6 +512,21 @@ - (void) updateResourcesForPath:(NSString*) path
if (res)
{
+ // Update generated sprite sheets
+ if (res.type == kCCBResTypeDirectory)
+ {
+ NSLog(@"CHECK DIR %@", res.filePath);
+
+ RMDirectory* dir = res.data;
+ BOOL oldValue = dir.isDynamicSpriteSheet;
+ [dir updateIsDynamicSpriteSheet];
+ if (oldValue != dir.isDynamicSpriteSheet)
+ {
+ resourcesChanged = YES;
+ NSLog(@"RESOURCES CHANGED!");
+ }
+ }
+
if ([res.modifiedTime compare:modifiedTime] == NSOrderedSame)
{
// Skip files that are not modified
@@ -504,7 +554,8 @@ - (void) updateResourcesForPath:(NSString*) path
|| res.type == kCCBResTypeBMFont
|| res.type == kCCBResTypeTTF
|| res.type == kCCBResTypeCCBFile
- || res.type == kCCBResTypeAudio)
+ || res.type == kCCBResTypeAudio
+ || res.type == kCCBResTypeGeneratedSpriteSheetDef)
{
needsUpdate = YES;
}
@@ -745,6 +796,7 @@ - (void) createCachedImageFromAuto:(NSString*)autoFile saveAs:(NSString*)dstFile
{
NSData* srcImageData = [NSData dataWithContentsOfFile:autoFile];
NSImage* srcImage = [[NSImage alloc] initWithData:srcImageData];
+ NSBitmapImageRep* srcImageRep = [[srcImage representations] objectAtIndex:0];
float dstScale = 1;
if ([res isEqualToString:@"hd"]) dstScale = 2;
@@ -760,17 +812,27 @@ - (void) createCachedImageFromAuto:(NSString*)autoFile saveAs:(NSString*)dstFile
dstScale = [CocosBuilderAppDelegate appDelegate].projectSettings.publishResolutionHTML5_scale;
}
- NSSize oldSize = [srcImage size];
-
float srcScale = [CocosBuilderAppDelegate appDelegate].projectSettings.resourceAutoScaleFactor;
float scaleFactor = dstScale/srcScale;
- NSLog(@"scaleFactor: %f srcScale: %f dstScale: %f res: %@", scaleFactor, srcScale, dstScale, res);
+ NSSize oldSizePixels = NSMakeSize([srcImageRep pixelsWide],[srcImageRep pixelsHigh]);
+ NSSize oldSize = [srcImage size];
+
NSSize newSize;
- newSize.width = oldSize.width*scaleFactor;
- newSize.height = oldSize.height*scaleFactor;
+ newSize.width = oldSizePixels.width*scaleFactor;
+ newSize.height = oldSizePixels.height*scaleFactor;
+
+ if ([[dstFile lastPathComponent] isEqualToString:@"coin01.png"])
+ {
+ NSLog(@"***** coin01.png *****");
+
+ NSLog(@"res: %@ scaleFactor: %f",res, scaleFactor);
+ NSLog(@"old: %f x %f", oldSize.width, oldSize.height);
+ NSLog(@"new: %f x %f", newSize.width, newSize.height);
+ NSLog(@"representations: %@", [srcImage representations]);
+ }
NSImage *resizedImage = [[NSImage alloc] initWithSize: newSize];
View
17 CocosBuilder/ccBuilder/ResourceManagerOutlineHandler.m
@@ -252,7 +252,22 @@ - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTab
}
else
{
- icon = [self smallIconForFile:res.filePath];
+ if (res.type == kCCBResTypeDirectory)
+ {
+ RMDirectory* dir = res.data;
+ if (dir.isDynamicSpriteSheet)
+ {
+ icon = [NSImage imageNamed:@"reshandler-spritesheet-folder.png"];
+ }
+ else
+ {
+ icon = [self smallIconForFile:res.filePath];
+ }
+ }
+ else
+ {
+ icon = [self smallIconForFile:res.filePath];
+ }
}
}
else if ([item isKindOfClass:[RMSpriteFrame class]])
View
9 CocosBuilder/libs/Tupac/Tupac.h
@@ -8,6 +8,11 @@
#import <Foundation/Foundation.h>
+enum {
+ kTupacImageFormatPNG,
+ kTupacImageFormatPVR,
+};
+
@interface Tupac : NSObject
@property(nonatomic) BOOL border;
@@ -15,7 +20,11 @@
@property(nonatomic, copy) NSArray *filenames;
@property(nonatomic, copy) NSString *outputName;
@property(nonatomic, copy) NSString *outputFormat;
+@property(nonatomic,assign) int imageFormat;
+
++ (Tupac*) tupac;
+- (void) createTextureAtlasFromDirectoryPaths:(NSArray *)dirs;
- (void)createTextureAtlas;
@end
View
184 CocosBuilder/libs/Tupac/Tupac.mm
@@ -35,12 +35,18 @@ @implementation Tupac {
TEXTURE_PACKER::TexturePacker* tp; // we hide this ivar in the implementation - requires LLVM Compiler 2.x
}
-@synthesize scale=scale_, border=border_, filenames=filenames_, outputName=outputName_, outputFormat=outputFormat_;
+@synthesize scale=scale_, border=border_, filenames=filenames_, outputName=outputName_, outputFormat=outputFormat_, imageFormat=imageFormat_;
+
++ (Tupac*) tupac
+{
+ return [[[Tupac alloc] init] autorelease];
+}
- (id)init {
if ((self = [super init])) {
scale_ = 1.0;
border_ = NO;
+ imageFormat_ = kTupacImageFormatPNG;
tp = TEXTURE_PACKER::createTexturePacker();
}
@@ -161,76 +167,87 @@ - (void)createTextureAtlas {
}
}
[NSGraphicsContext restoreGraphicsState];
-
- //
- // PNG Export
- //
-
-// NSString *pngFilename = [self.outputName stringByAppendingPathExtension:@"png"];
-// [[outRep representationUsingType:NSPNGFileType properties:nil] writeToFile:pngFilename atomically:YES];
-
-
- //
- // PVR Export
- //
-
- pvrtc_info_output(stdout);
-
- size_t pvrOutputSize = pvrtc_size((int)outRep.pixelsWide, // width
- (int)outRep.pixelsHigh, // height
- 0, // generate mipmaps
- 0); // use 2bpp compression
- NSMutableData *pvrData = [[NSMutableData alloc] initWithLength:pvrOutputSize];
- NSString *pvrFilename = [self.outputName stringByAppendingPathExtension:@"pvr"];
-
- if (outW == outH) {
- // if square, we use PVRC (compressed) format for our data
+ NSString* textureFileName = NULL;
- pvrtc_compress([outRep bitmapData], // input data
- [pvrData mutableBytes], // output data
- (int)outRep.pixelsWide, // resize width
- (int)outRep.pixelsHigh, // resize height
- 0, // generate mipmaps
- 1, // alpha on
- 0, // texture wraps
- 0); // use 2bpp compression
+ if (imageFormat_ == kTupacImageFormatPNG)
+ {
+ //
+ // PNG Export
+ //
+
+ NSString *pngFilename = [self.outputName stringByAppendingPathExtension:@"png"];
+ [[outRep representationUsingType:NSPNGFileType properties:nil] writeToFile:pngFilename atomically:YES];
+
+ textureFileName = pngFilename;
}
- else {
- // if not square, we construct a file with a simple header followed by uncompressed data
-
- PVRTexHeader header;
+ else if (imageFormat_ == kTupacImageFormatPVR)
+ {
+ //
+ // PVR Export
+ //
+
- header.headerLength = sizeof(PVRTexHeader);
+ pvrtc_info_output(stdout);
- header.width = (uint32_t)outRep.pixelsWide;
- header.height = (uint32_t)outRep.pixelsHigh;
+ size_t pvrOutputSize = pvrtc_size((int)outRep.pixelsWide, // width
+ (int)outRep.pixelsHigh, // height
+ 0, // generate mipmaps
+ 0); // use 2bpp compression
- header.numMipmaps = 0;
+ NSMutableData *pvrData = [[NSMutableData alloc] initWithLength:pvrOutputSize];
+ NSString *pvrFilename = [self.outputName stringByAppendingPathExtension:@"pvr"];
- header.bpp = 32;
- header.flags = 32786;
- header.dataLength = (uint32_t)(outRep.pixelsWide * outRep.pixelsHigh * 4);
+ if (outW == outH) {
+ // if square, we use PVRC (compressed) format for our data
- header.bitmaskRed = 0xFF000000;
- header.bitmaskBlue = 0x0000FF00;
- header.bitmaskGreen = 0x00FF0000;
- header.bitmaskAlpha = 0x000000FF;
-
- header.pvrTag = 559044176;
+ pvrtc_compress([outRep bitmapData], // input data
+ [pvrData mutableBytes], // output data
+ (int)outRep.pixelsWide, // resize width
+ (int)outRep.pixelsHigh, // resize height
+ 0, // generate mipmaps
+ 1, // alpha on
+ 0, // texture wraps
+ 0); // use 2bpp compression
+ }
+ else {
+ // if not square, we construct a file with a simple header followed by uncompressed data
+
+ PVRTexHeader header;
+
+ header.headerLength = sizeof(PVRTexHeader);
+
+ header.width = (uint32_t)outRep.pixelsWide;
+ header.height = (uint32_t)outRep.pixelsHigh;
+
+ header.numMipmaps = 0;
+
+ header.bpp = 32;
+ header.flags = 32786;
+ header.dataLength = (uint32_t)(outRep.pixelsWide * outRep.pixelsHigh * 4);
+
+ header.bitmaskRed = 0xFF000000;
+ header.bitmaskBlue = 0x0000FF00;
+ header.bitmaskGreen = 0x00FF0000;
+ header.bitmaskAlpha = 0x000000FF;
+
+ header.pvrTag = 559044176;
+
+ header.numSurfs = 1;
+
+ [pvrData setLength:0];
+ [pvrData appendBytes:&header length:sizeof(PVRTexHeader)];
+ [pvrData appendBytes:[outRep bitmapData] length:outRep.pixelsWide * outRep.pixelsHigh * 4];
+ }
- header.numSurfs = 1;
+ [pvrData writeToFile:pvrFilename atomically:YES];
+ [pvrData release];
+
+ [outRep release];
- [pvrData setLength:0];
- [pvrData appendBytes:&header length:sizeof(PVRTexHeader)];
- [pvrData appendBytes:[outRep bitmapData] length:outRep.pixelsWide * outRep.pixelsHigh * 4];
+ textureFileName = pvrFilename;
}
-
- [pvrData writeToFile:pvrFilename atomically:YES];
- [pvrData release];
-
- [outRep release];
-
+
//
// Metadata File Export
//
@@ -259,8 +276,8 @@ - (void)createTextureAtlas {
forKey:[filename lastPathComponent]];
}
- [metadata setObject:pvrFilename forKey:@"realTextureFilename"];
- [metadata setObject:pvrFilename forKey:@"textureFilename"];
+ [metadata setObject:textureFileName forKey:@"realTextureFilename"];
+ [metadata setObject:textureFileName forKey:@"textureFilename"];
[metadata setObject:[NSNumber numberWithInt:2] forKey:@"format"];
[metadata setObject:NSStringFromSize(NSMakeSize(outW, outH)) forKey:@"size"];
@@ -272,6 +289,49 @@ - (void)createTextureAtlas {
exit(EXIT_FAILURE);
}
}
+
+- (void) createTextureAtlasFromDirectoryPaths:(NSArray *)dirs
+{
+ NSFileManager* fm = [NSFileManager defaultManager];
+
+ // Build a list of all file names from all directories
+ NSMutableSet* allFiles = [NSMutableSet set];
+
+ for (NSString* dir in dirs)
+ {
+ NSArray* files = [fm contentsOfDirectoryAtPath:dir error:NULL];
+
+ for (NSString* file in files)
+ {
+ if ([[[file pathExtension] lowercaseString] isEqualToString:@"png"])
+ {
+ [allFiles addObject:[file lastPathComponent]];
+ }
+ }
+ }
+
+ // Add all the absolute file names to an array from the correct directories
+ NSMutableArray* absoluteFilepaths = [NSMutableArray array];
+ for (NSString* file in allFiles)
+ {
+ BOOL foundFile = NO;
+ for (NSString* dir in dirs)
+ {
+ NSString* absFilepath = [dir stringByAppendingPathComponent:file];
+
+ if ([fm fileExistsAtPath:absFilepath])
+ {
+ [absoluteFilepaths addObject:absFilepath];
+ //foundFile = YES;
+ break;
+ }
+ }
+ }
+
+ // Generate the sprite sheet
+ self.filenames = absoluteFilepaths;
+ [self createTextureAtlas];
+}
@end
NSString *TupacOutputFormatCocos2D = @"cocos2d";
View
BIN  Graphics/Folder icon.psd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.