Skip to content

Commit 5c3e259

Browse files
committed
CCSpriteFrameCache: Method added to load all Sprite sheet lookup files in all search paths and merge them in ivar.
1 parent 519b121 commit 5c3e259

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

cocos2d/CCSpriteFrameCache.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@
114114
*/
115115
-(void) loadSpriteFrameLookupDictionaryFromFile:(NSString*)filename;
116116

117+
/**
118+
* Loads all sprite sheet lookup files in all search paths and registers all the referenced sprite sheets with the sprite frame cache.
119+
*
120+
* @param filename Sprite sheet lookup file.
121+
*/
122+
- (void)loadSpriteFrameLookupsInAllSearchPathsWithName:(NSString *)filename;
123+
117124
/// -----------------------------------------------------------------------
118125
/// @name Sprite Frame Cache Removal
119126
/// -----------------------------------------------------------------------

cocos2d/CCSpriteFrameCache.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,30 @@ -(void) loadSpriteFrameLookupDictionaryFromFile:(NSString*)filename
129129
}
130130
}
131131

132+
- (void)loadSpriteFrameLookupsInAllSearchPathsWithName:(NSString *)filename
133+
{
134+
NSArray *paths = [[CCFileUtils sharedFileUtils] fullPathsOfFileNameInAllSearchPaths:filename];
135+
136+
for (NSString *spriteFrameLookupFullPath in paths)
137+
{
138+
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:spriteFrameLookupFullPath];
139+
140+
NSDictionary *metadata = dict[@"metadata"];
141+
NSInteger version = [metadata[@"version"] integerValue];
142+
if (version != 1)
143+
{
144+
CCLOG(@"cocos2d: ERROR: Invalid filenameLookup dictionary version: %ld. Filename: %@", (long) version, filename);
145+
return;
146+
}
147+
148+
NSArray *spriteFrameFiles = dict[@"spriteFrameFiles"];
149+
for (NSString *spriteFrameFile in spriteFrameFiles)
150+
{
151+
[self registerSpriteFramesFile:spriteFrameFile];
152+
}
153+
}
154+
}
155+
132156
- (void) registerSpriteFramesFile:(NSString*)plist
133157
{
134158
NSAssert(plist, @"plist filename should not be nil");

0 commit comments

Comments
 (0)