Skip to content

Commit a47d8fd

Browse files
committed
Merge git://github.com/jjxtra/cocos2d-iphone into v3.0
2 parents da24970 + 56aac87 commit a47d8fd

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

cocos2d/CCLabelBMFont.m

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ - (NSMutableString *)parseConfigFile:(NSString*)fntFile
206206
element->key = element->fontDef.charID;
207207
HASH_ADD_INT(_fontDefDictionary, key, element);
208208

209-
[validCharsString appendString:[NSString stringWithFormat:@"%C", element->fontDef.charID]];
209+
[validCharsString appendFormat:@"%C", element->fontDef.charID];
210210
}
211211
// else if([line hasPrefix:@"kernings count"]) {
212212
// [self parseKerningCapacity:line];
@@ -424,6 +424,39 @@ -(void) parseKerningEntry:(NSString*) line
424424
#pragma mark -
425425
#pragma mark CCLabelBMFont
426426

427+
static NSString* stringFromUInt32(UInt32 i)
428+
{
429+
static NSString* strings[] = { @"0", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9",
430+
@"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19",
431+
@"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27", @"28", @"29",
432+
@"30", @"31", @"32", @"33", @"34", @"35", @"36", @"37", @"38", @"39",
433+
@"40", @"41", @"42", @"43", @"44", @"45", @"46", @"47", @"48", @"49",
434+
@"50", @"51", @"52", @"53", @"54", @"55", @"56", @"57", @"58", @"59",
435+
@"60", @"61", @"62", @"63", @"64", @"65", @"66", @"67", @"68", @"69",
436+
@"70", @"71", @"72", @"73", @"74", @"75", @"76", @"77", @"78", @"79",
437+
@"80", @"81", @"82", @"83", @"84", @"85", @"86", @"87", @"88", @"89",
438+
@"90", @"91", @"92", @"93", @"94", @"95", @"96", @"97", @"98", @"99",
439+
@"100", @"101", @"102", @"103", @"104", @"105", @"106", @"107", @"108", @"109",
440+
@"110", @"111", @"112", @"113", @"114", @"115", @"116", @"117", @"118", @"119",
441+
@"120", @"121", @"122", @"123", @"124", @"125", @"126", @"127", @"128", @"129",
442+
@"130", @"131", @"132", @"133", @"134", @"135", @"136", @"137", @"138", @"139",
443+
@"140", @"141", @"142", @"143", @"144", @"145", @"146", @"147", @"148", @"149",
444+
@"150", @"151", @"152", @"153", @"154", @"155", @"156", @"157", @"158", @"159",
445+
@"160", @"161", @"162", @"163", @"164", @"165", @"166", @"167", @"168", @"169",
446+
@"170", @"171", @"172", @"173", @"174", @"175", @"176", @"177", @"178", @"179",
447+
@"180", @"181", @"182", @"183", @"184", @"185", @"186", @"187", @"188", @"189",
448+
@"190", @"191", @"192", @"193", @"194", @"195", @"196", @"197", @"198", @"199",
449+
@"200", @"201", @"202", @"203", @"204", @"205", @"206", @"207", @"208", @"209",
450+
@"210", @"211", @"212", @"213", @"214", @"215", @"216", @"217", @"218", @"219",
451+
@"220", @"221", @"222", @"223", @"224", @"225", @"226", @"227", @"228", @"229",
452+
@"230", @"231", @"232", @"233", @"234", @"235", @"236", @"237", @"238", @"239",
453+
@"240", @"241", @"242", @"243", @"244", @"245", @"246", @"247", @"248", @"249",
454+
@"250", @"251", @"252", @"253", @"254", @"255" };
455+
456+
457+
return ((i & 0xFFFFFF00) ? @(i).stringValue : strings[i]);
458+
}
459+
427460
@interface CCLabelBMFont ()
428461

429462
-(int) kerningAmountForFirst:(unichar)first second:(unichar)second;
@@ -553,7 +586,7 @@ - (void)updateLabel
553586
CCSprite *characterSprite;
554587
int justSkipped = 0;
555588
int idx = j+skip+justSkipped;
556-
NSString* idxStr = [NSString stringWithFormat:@"%d", idx];
589+
NSString* idxStr = stringFromUInt32(idx);
557590
while(!(characterSprite = (CCSprite *)[self getChildByName:idxStr recursively:NO]))
558591
justSkipped++;
559592
skip += justSkipped;
@@ -678,7 +711,7 @@ - (void)updateLabel
678711
index = i + j + lineNumber;
679712
if (index < 0)
680713
continue;
681-
NSString* indexStr1 = [NSString stringWithFormat:@"%d",(int)index];
714+
NSString* indexStr1 = stringFromUInt32((UInt32)index);
682715
CCSprite *characterSprite = (CCSprite *)[self getChildByName:indexStr1 recursively:NO];
683716
characterSprite.position = ccpAdd(characterSprite.position, ccp(shift, 0));
684717
}
@@ -777,7 +810,7 @@ -(void) createFontChars
777810
CCSprite *fontChar;
778811

779812
BOOL hasSprite = YES;
780-
NSString* iStr = [NSString stringWithFormat:@"%d",(int)i];
813+
NSString* iStr = stringFromUInt32((UInt32)i);
781814
fontChar = (CCSprite*) [self getChildByName:iStr recursively:NO];
782815
if( fontChar )
783816
{
@@ -797,7 +830,7 @@ -(void) createFontChars
797830
hasSprite = NO;
798831
} else {
799832
fontChar = [[CCSprite alloc] initWithTexture:_textureAtlas.texture rect:rect];
800-
NSString* iStr1 = [NSString stringWithFormat:@"%d",(int)i];
833+
NSString* iStr1 = stringFromUInt32((UInt32)i);
801834
[self addChild:fontChar z:i name:iStr1];
802835
}
803836

cocos2d/Platforms/iOS/CCDirectorIOS.m

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,29 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
287287
// [_delegate willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
288288
//}
289289

290-
291-
-(void) viewWillAppear:(BOOL)animated
290+
-(void) startAnimationIfPossible
292291
{
293-
[super viewWillAppear:animated];
294-
295292
UIApplicationState state = UIApplication.sharedApplication.applicationState;
296293
if (state != UIApplicationStateBackground)
297294
{
298295
[self startAnimation];
299296
}
297+
else
298+
{
299+
// we are backgrounded, try again in 1 second, we want to make sure that this call eventually goes through in the event
300+
// that there was a full screen view controller that caused additional stop animation calls
301+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
302+
{
303+
[self startAnimationIfPossible];
304+
});
305+
}
306+
}
307+
308+
-(void) viewWillAppear:(BOOL)animated
309+
{
310+
[super viewWillAppear:animated];
311+
312+
[self startAnimationIfPossible];
300313
}
301314

302315
-(void) viewDidAppear:(BOOL)animated

0 commit comments

Comments
 (0)