Skip to content

Commit b4fd9c9

Browse files
committed
Merge branch 'v3.0' of https://github.com/cocos2d/cocos2d-iphone into v3.0
2 parents 6904cde + 13ea509 commit b4fd9c9

File tree

7 files changed

+96
-43
lines changed

7 files changed

+96
-43
lines changed

cocos2d-tests-ios.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
D340E10F185660BE006E605C /* TilemapTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D340E10D185660BE006E605C /* TilemapTest.m */; };
7171
D356F65918BC02BC00FE4ACF /* CCRendererTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D356F65818BC02BC00FE4ACF /* CCRendererTest.m */; };
7272
D3870C5A18B43FC20033D885 /* SpritePerformanceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D3870C5918B43FC20033D885 /* SpritePerformanceTest.m */; };
73+
D38C223418EC8D2C00DD7599 /* Fonts in Resources */ = {isa = PBXBuildFile; fileRef = D38C223318EC8D2C00DD7599 /* Fonts */; };
7374
D3B2A7E5187DD60B00406C5A /* CCBMFontTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D3B2A7E4187DD60B00406C5A /* CCBMFontTest.m */; };
7475
D3C9C867188078B900C58900 /* CCSchedulerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D3C9C866188078B900C58900 /* CCSchedulerTest.m */; };
7576
/* End PBXBuildFile section */
@@ -187,6 +188,7 @@
187188
D340E10D185660BE006E605C /* TilemapTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TilemapTest.m; path = "cocos2d-ui-tests/tests/TilemapTest.m"; sourceTree = SOURCE_ROOT; };
188189
D356F65818BC02BC00FE4ACF /* CCRendererTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCRendererTest.m; path = "cocos2d-ui-tests/tests/CCRendererTest.m"; sourceTree = SOURCE_ROOT; };
189190
D3870C5918B43FC20033D885 /* SpritePerformanceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpritePerformanceTest.m; path = "cocos2d-ui-tests/tests/SpritePerformanceTest.m"; sourceTree = SOURCE_ROOT; };
191+
D38C223318EC8D2C00DD7599 /* Fonts */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Fonts; path = Resources/Fonts; sourceTree = SOURCE_ROOT; };
190192
D3B2A7E4187DD60B00406C5A /* CCBMFontTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCBMFontTest.m; path = "cocos2d-ui-tests/tests/CCBMFontTest.m"; sourceTree = SOURCE_ROOT; };
191193
D3C9C866188078B900C58900 /* CCSchedulerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCSchedulerTest.m; path = "cocos2d-ui-tests/tests/CCSchedulerTest.m"; sourceTree = SOURCE_ROOT; };
192194
/* End PBXFileReference section */
@@ -251,6 +253,7 @@
251253
758A6C6E1843E84D00D1A8D2 /* Test Resources */ = {
252254
isa = PBXGroup;
253255
children = (
256+
D38C223318EC8D2C00DD7599 /* Fonts */,
254257
75F76496185A831B00E2FAFE /* Sounds */,
255258
758A6C7F184410EE00D1A8D2 /* Particles */,
256259
758A6C6A1843E5BE00D1A8D2 /* TileMaps */,
@@ -594,6 +597,7 @@
594597
B7E2621417E7D34D007067F0 /* Icon-Small.png in Resources */,
595598
B7C6237617EA695100928F91 /* Resources-shared in Resources */,
596599
B7E2621517E7D34D007067F0 /* [email protected] in Resources */,
600+
D38C223418EC8D2C00DD7599 /* Fonts in Resources */,
597601
B7E2621617E7D34D007067F0 /* Icon.png in Resources */,
598602
B7E2621717E7D34D007067F0 /* [email protected] in Resources */,
599603
B7E2621917E7D34D007067F0 /* iTunesArtwork in Resources */,

cocos2d-ui-tests/ios/AppDelegate.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3838

3939
sharedFileUtils.searchPath =
4040
[NSArray arrayWithObjects:
41+
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"],
42+
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Fonts"],
4143
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Resources-shared"],
4244
[[NSBundle mainBundle] resourcePath],
4345
nil];

cocos2d-ui-tests/tests/CCBMFontTest.m

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,51 @@
99
#import "TestBase.h"
1010
#import "CCTextureCache.h"
1111

12+
static NSString *TEST_STRINGS[] = {
13+
@"ABCDEFGHIJKLM\nNOPQRSTUVWXYZ",
14+
@"abcdefghijklm\nnopqrstuvwxyz",
15+
@",.?!;:'\"",
16+
@"()[]{}<>\\|/\n",
17+
@"@#$%^&*+-=_",
18+
@" ab c de\n fg hi j k",
19+
};
20+
static const int TEST_STRING_COUNT = sizeof(TEST_STRINGS)/sizeof(*TEST_STRINGS);
21+
1222
@interface CCBMFontTest : TestBase @end
1323

1424
@implementation CCBMFontTest
1525

16-
- (void) setupSimpleAudioTest
26+
-(void)testFont:(NSString *)font
1727
{
18-
self.subTitle = @"Test bitmap fonts.";
19-
20-
NSString *string =
21-
@"@Q&wyHDB4#qphdi\n"
22-
@"WYK>kgbE?97652f\n"
23-
@"MlXS<'U8Z{/usonec:\n"
24-
@"$}V0C%T3Lj1a)=~_\n"
25-
@"A!RGmPOJ\t]*-`\n"
26-
@"^;xv+NzF\"r[:(|l";
27-
28-
CCLabelBMFont *label = [CCLabelBMFont labelWithString:string fntFile:@"din.fnt"];
28+
self.subTitle = [NSString stringWithFormat:@"Test bitmap fonts. (%@)", font];
29+
30+
CCLabelBMFont *label = [CCLabelBMFont labelWithString:TEST_STRINGS[0] fntFile:font];
2931
label.positionType = CCPositionTypeNormalized;
3032
label.position = ccp(0.5, 0.5);
3133
[self.contentNode addChild:label];
34+
35+
__block int i = 0;
36+
const CCTime delay = 1.0;
37+
[self scheduleBlock:^(CCTimer *timer) {
38+
i = (i + 1)%TEST_STRING_COUNT;
39+
label.string = TEST_STRINGS[i];
40+
41+
[timer repeatOnceWithInterval:delay];
42+
} delay:delay];
3243
}
3344

45+
-(void)setupBMFont01Test {[self testFont:@"din.fnt"];}
46+
-(void)setupBMFont02Test {[self testFont:@"Fonts/arial-unicode-26.fnt"];}
47+
-(void)setupBMFont03Test {[self testFont:@"Fonts/arial16.fnt"];}
48+
-(void)setupBMFont04Test {[self testFont:@"Fonts/bitmapFontTest.fnt"];}
49+
-(void)setupBMFont06Test {[self testFont:@"Fonts/bitmapFontTest3.fnt"];}
50+
-(void)setupBMFont07Test {[self testFont:@"Fonts/bitmapFontTest4.fnt"];}
51+
-(void)setupBMFont08Test {[self testFont:@"Fonts/bitmapFontTest5.fnt"];}
52+
-(void)setupBMFont09Test {[self testFont:@"Fonts/boundsTestFont.fnt"];}
53+
-(void)setupBMFont10Test {[self testFont:@"Fonts/font-issue1343.fnt"];}
54+
-(void)setupBMFont11Test {[self testFont:@"Fonts/futura-48.fnt"];}
55+
-(void)setupBMFont12Test {[self testFont:@"Fonts/konqa32.fnt"];}
56+
-(void)setupBMFont14Test {[self testFont:@"Fonts/markerFelt.fnt"];}
57+
-(void)setupBMFont15Test {[self testFont:@"Fonts/west_england-64.fnt"];}
58+
3459
@end

cocos2d/CCLabelBMFont.m

Lines changed: 30 additions & 20 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];
@@ -435,7 +435,11 @@ -(void) setString:(NSString*) newString updateLabel:(BOOL)update;
435435
#pragma mark -
436436
#pragma mark CCLabelBMFont
437437

438-
@implementation CCLabelBMFont
438+
@implementation CCLabelBMFont {
439+
// Replacement for the old CCNode.tag property which was
440+
// used heavily in the original code.
441+
NSMutableArray *_childForTag;
442+
}
439443

440444
@synthesize alignment = _alignment;
441445

@@ -526,13 +530,31 @@ -(id) initWithString:(NSString*)theString fntFile:(NSString*)fntFile width:(floa
526530

527531
_reusedChar = [[CCSprite alloc] initWithTexture:_textureAtlas.texture rect:CGRectMake(0, 0, 0, 0) rotated:NO];
528532
[_reusedChar setBatchNode:self];
533+
_childForTag = [NSMutableArray array];
529534

530535
[self setString:theString updateLabel:YES];
531536
}
532537

533538
return self;
534539
}
535540

541+
-(CCSprite *)childForTag:(NSUInteger)tag
542+
{
543+
if(tag < _childForTag.count){
544+
id child = _childForTag[tag];
545+
return (child == [NSNull null] ? nil : child);
546+
} else {
547+
return nil;
548+
}
549+
}
550+
551+
-(void)setTag:(NSUInteger)tag forChild:(CCSprite *)child
552+
{
553+
// Insert NSNull to fill holes if necessary.
554+
while(_childForTag.count < tag) [_childForTag addObject:[NSNull null]];
555+
[_childForTag addObject:child];
556+
}
557+
536558

537559
#pragma mark LabelBMFont - Alignment
538560

@@ -552,9 +574,7 @@ - (void)updateLabel
552574
for (int j = 0; j < [_children count]; j++) {
553575
CCSprite *characterSprite;
554576
int justSkipped = 0;
555-
int idx = j+skip+justSkipped;
556-
NSString* idxStr = [NSString stringWithFormat:@"%d", idx];
557-
while(!(characterSprite = (CCSprite *)[self getChildByName:idxStr recursively:NO]))
577+
while(!(characterSprite = [self childForTag:j+skip+justSkipped]))
558578
justSkipped++;
559579
skip += justSkipped;
560580

@@ -649,13 +669,7 @@ - (void)updateLabel
649669
continue;
650670

651671
//Find position of last character on the line
652-
CCSprite *lastChar;
653-
for(CCSprite* child in [self children]) {
654-
if([child atlasIndex]==index) {
655-
lastChar = child;
656-
break;
657-
}
658-
}
672+
CCSprite *lastChar = [self childForTag:index];
659673

660674
lineWidth = lastChar.position.x + lastChar.contentSize.width/2;
661675

@@ -678,8 +692,7 @@ - (void)updateLabel
678692
index = i + j + lineNumber;
679693
if (index < 0)
680694
continue;
681-
NSString* indexStr1 = [NSString stringWithFormat:@"%d",(int)index];
682-
CCSprite *characterSprite = (CCSprite *)[self getChildByName:indexStr1 recursively:NO];
695+
CCSprite *characterSprite = [self childForTag:index];
683696
characterSprite.position = ccpAdd(characterSprite.position, ccp(shift, 0));
684697
}
685698
}
@@ -774,11 +787,8 @@ -(void) createFontChars
774787
rect.origin.x += _imageOffset.x;
775788
rect.origin.y += _imageOffset.y;
776789

777-
CCSprite *fontChar;
778-
779790
BOOL hasSprite = YES;
780-
NSString* iStr = [NSString stringWithFormat:@"%d",(int)i];
781-
fontChar = (CCSprite*) [self getChildByName:iStr recursively:NO];
791+
CCSprite *fontChar = [self childForTag:i];
782792
if( fontChar )
783793
{
784794
// Reusing previous Sprite
@@ -797,8 +807,8 @@ -(void) createFontChars
797807
hasSprite = NO;
798808
} else {
799809
fontChar = [[CCSprite alloc] initWithTexture:_textureAtlas.texture rect:rect];
800-
NSString* iStr1 = [NSString stringWithFormat:@"%d",(int)i];
801-
[self addChild:fontChar z:i name:iStr1];
810+
[self addChild:fontChar z:i];
811+
[self setTag:i forChild:fontChar];
802812
}
803813

804814
// Apply label properties

cocos2d/CCLabelTTF.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,9 @@ - (CCTexture*) createTextureWithAttributedString:(NSAttributedString*)attributed
650650
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
651651
CGContextSetLineWidth(context, outlineWidth * 2);
652652
CGContextSetLineJoin(context, kCGLineJoinRound);
653-
CGContextSetStrokeColorWithColor(context, [color CGColor]);
654-
653+
655654
NSMutableAttributedString* outlineString = [attributedString mutableCopy];
656-
[outlineString removeAttribute:NSForegroundColorAttributeName range:NSMakeRange(0, outlineString.length)];
655+
[outlineString addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, outlineString.length)];
657656

658657
[outlineString drawInRect:drawArea];
659658

cocos2d/CCNode.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,25 +415,25 @@ A common user pattern in building a Cocos2d game is to subclass CCNode, add it t
415415
During onEnter you can't access a sibling node.
416416
If you override onEnter, you shall call [super onEnter].
417417
*/
418-
-(void) onEnter;
418+
-(void) onEnter __attribute__((objc_requires_super));
419419

420420
/** Event that is called when the CCNode enters in the 'stage'.
421421
If the CCNode enters the 'stage' with a transition, this event is called when the transition finishes.
422422
If you override onEnterTransitionDidFinish, you shall call [super onEnterTransitionDidFinish].
423423
*/
424-
-(void) onEnterTransitionDidFinish;
424+
-(void) onEnterTransitionDidFinish __attribute__((objc_requires_super));
425425

426426
/** Event that is called every time the CCNode leaves the 'stage'.
427427
If the CCNode leaves the 'stage' with a transition, this event is called when the transition finishes.
428428
During onExit you can't access a sibling node.
429429
If you override onExit, you shall call [super onExit].
430430
*/
431-
-(void) onExit;
431+
-(void) onExit __attribute__((objc_requires_super));
432432

433433
/** Callback that is called every time the CCNode leaves the 'stage'.
434434
If the CCNode leaves the 'stage' with a transition, this callback is called when the transition starts.
435435
*/
436-
-(void) onExitTransitionDidStart;
436+
-(void) onExitTransitionDidStart __attribute__((objc_requires_super));
437437

438438
/** The scene this node is added to, or nil if it's not part of a scene. */
439439
@property(nonatomic, readonly) CCScene *scene;

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)