Skip to content

Commit f80c5fd

Browse files
committed
Some tweaks to the cocos2d code:
1. CCActionEaseOut wasn't easing very well. 2. Fixed a few basic compiler warnings. 3. Use [NSAttributedString isEqualToAttributedString:] for comparison. 4. Added enhancement to CCNode so that when a nodes content size is changed, it's children are updated as well which is essential when using normalised coordinates/sizes in children. 5. Added some more photoshop blend modes. 6. Patched NSAttributedString+CCAdditions.m to prevent font overrides when we don't want them.
1 parent 7b85ea2 commit f80c5fd

File tree

8 files changed

+80
-15
lines changed

8 files changed

+80
-15
lines changed

cocos2d/CCActionEase.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ -(void) update: (CCTime) t
176176
@implementation CCActionEaseOut
177177
-(void) update: (CCTime) t
178178
{
179-
[_inner update: powf(t,1/_rate)];
179+
[_inner update: 1.0f - powf(1.0f - t, _rate)];
180180
}
181181
@end
182182

cocos2d/CCActionInterval.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ -(void) update:(CCTime) dt
336336
{
337337
while (dt > _nextDt && _total < _times)
338338
{
339-
[_innerAction update:1.0];
339+
340+
[_innerAction update:1.0f];
340341
_total++;
341342

342343
[_innerAction stop];
@@ -345,7 +346,7 @@ -(void) update:(CCTime) dt
345346
}
346347

347348
// fix for issue #1288, incorrect end value of repeat
348-
if(dt >= 1.0 && _total < _times)
349+
if(dt >= 1.0f && _total < _times)
349350
{
350351
_total++;
351352
}
@@ -367,7 +368,7 @@ -(void) update:(CCTime) dt
367368
}
368369
else
369370
{
370-
[_innerAction update:fmod(dt * _times, 1.0)];
371+
[_innerAction update:fmodf(dt * _times,1.0f)];
371372
}
372373
}
373374

cocos2d/CCLabelTTF.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ - (void) _setAttributedString:(NSAttributedString *)attributedString
156156
{
157157
NSAssert(attributedString, @"Invalid attributedString");
158158

159-
if ( _attributedString.hash != attributedString.hash)
159+
if ( ![_attributedString isEqualToAttributedString: attributedString])
160+
// if ( _attributedString.hash != attributedString.hash)
160161
{
161162
_attributedString = [attributedString copy];
162163

cocos2d/CCNode.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,20 @@ - (void) contentSizeChanged
397397
// Update the children (if needed)
398398
for (CCNode* child in _children)
399399
{
400-
if (!CCPositionTypeIsBasicPoints(child->_positionType))
400+
[child parentsContentSizeChanged];
401+
}
402+
403+
}
404+
405+
- (void) parentsContentSizeChanged
401406
{
402-
// This is a position type affected by content size
403-
child->_isTransformDirty = _isInverseDirty = YES;
407+
if (!CCSizeTypeIsBasicPoints(_contentSizeType))
408+
{
409+
[self contentSizeChanged];
404410
}
411+
else if (!CCPositionTypeIsBasicPoints(_positionType))
412+
{
413+
_isTransformDirty = _isInverseDirty = YES;
405414
}
406415
}
407416

cocos2d/CCNode_Private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,6 @@ CGAffineTransform CGAffineTransformMakeRigid(CGPoint translate, CGFloat radians)
108108
-(void) detachChild:(CCNode *)child cleanup:(BOOL)doCleanup;
109109

110110
- (void) contentSizeChanged;
111+
- (void) parentsContentSizeChanged;
111112

112113
@end

cocos2d/CCRendererBasicTypes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ extern NSString * const CCBlendEquationAlpha;
129129
+(CCBlendMode *)addMode;
130130
/// Multiply blending mode. (Similar to PhotoShop's burn mode)
131131
+(CCBlendMode *)multiplyMode;
132+
/// A (better) multiply blending mode.
133+
+(CCBlendMode *)multiplicativeMode;
134+
/// A (better) add mode.
135+
+(CCBlendMode *)addWithAlphaMode;
136+
/// Similar to PhotoShop's screen mode.
137+
+(CCBlendMode *)screenMode;
138+
/// Similar to PhotoShop's dodge mode.
139+
+(CCBlendMode *)dodgeMode;
132140

133141
@end
134142

cocos2d/CCRendererBasicTypes.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ -(instancetype)initWithOptions:(NSDictionary *)options
128128
static CCBlendMode *CCBLEND_ADD = nil;
129129
static CCBlendMode *CCBLEND_MULTIPLY = nil;
130130

131+
static CCBlendMode *CCBLEND_ADD_WITH_ALPHA = nil;
132+
static CCBlendMode *CCBLEND_SCREEN = nil;
133+
static CCBlendMode *CCBLEND_MULTIPLICATIVE = nil;
134+
static CCBlendMode *CCBLEND_DODGE = nil;
135+
131136
NSDictionary *CCBLEND_DISABLED_OPTIONS = nil;
132137

133138
+(void)initialize
@@ -160,6 +165,26 @@ +(void)initialize
160165
CCBlendFuncSrcColor: @(GL_DST_COLOR),
161166
CCBlendFuncDstColor: @(GL_ZERO),
162167
}];
168+
169+
CCBLEND_ADD_WITH_ALPHA = [self blendModeWithOptions:@{
170+
CCBlendFuncSrcColor: @(GL_SRC_ALPHA),
171+
CCBlendFuncDstColor: @(GL_ZERO),
172+
}];
173+
174+
CCBLEND_SCREEN = [self blendModeWithOptions:@{
175+
CCBlendFuncSrcColor: @(GL_ONE_MINUS_DST_COLOR),
176+
CCBlendFuncDstColor: @(GL_ONE),
177+
}];
178+
179+
CCBLEND_MULTIPLICATIVE = [self blendModeWithOptions:@{
180+
CCBlendFuncSrcColor: @(GL_DST_COLOR),
181+
CCBlendFuncDstColor: @(GL_ONE_MINUS_SRC_ALPHA),
182+
}];
183+
184+
CCBLEND_DODGE = [self blendModeWithOptions:@{
185+
CCBlendFuncSrcColor: @(GL_ONE_MINUS_SRC_ALPHA),
186+
CCBlendFuncDstColor: @(GL_ONE),
187+
}];
163188
}
164189

165190
+(void)flushCache
@@ -197,6 +222,26 @@ +(CCBlendMode *)multiplyMode
197222
return CCBLEND_MULTIPLY;
198223
}
199224

225+
+(CCBlendMode *)multiplicativeMode
226+
{
227+
return CCBLEND_MULTIPLICATIVE;
228+
}
229+
230+
+(CCBlendMode *)addWithAlphaMode
231+
{
232+
return CCBLEND_ADD_WITH_ALPHA;
233+
}
234+
235+
+(CCBlendMode *)screenMode
236+
{
237+
return CCBLEND_SCREEN;
238+
}
239+
240+
+(CCBlendMode *)dodgeMode
241+
{
242+
return CCBLEND_DODGE;
243+
}
244+
200245
@end
201246

202247

cocos2d/Support/NSAttributedString+CCAdditions.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ BOOL NSMutableAttributedStringFixPlatformSpecificAttributes(NSMutableAttributedS
261261
[string addAttribute:(id)kCTForegroundColorFromContextAttributeName value:(__bridge id)color range:fullRange];
262262
CGColorRelease(color);
263263
}
264-
if (NSAttributedStringHasAttribute(string, NSFontAttributeName)) {
265-
id font = [string attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL];
266-
CTFontRef ctFont = CTFontCreateWithPlatformSpecificFont(font);
267-
[string addAttribute:(id)kCTFontAttributeName value:(__bridge id)ctFont range:fullRange];
268-
CFRelease(ctFont);
269-
}
264+
// if (NSAttributedStringHasAttribute(string, NSFontAttributeName)) {
265+
// id font = [string attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL];
266+
// CTFontRef ctFont = CTFontCreateWithPlatformSpecificFont(font);
267+
// [string addAttribute:(id)kCTFontAttributeName value:(__bridge id)ctFont range:fullRange];
268+
// CFRelease(ctFont);
269+
// }
270270

271271
// Shadow
272272
if (NSAttributedStringHasAttribute(string, NSShadowAttributeName))
@@ -330,7 +330,7 @@ BOOL NSMutableAttributedStringFixPlatformSpecificAttributes(NSMutableAttributedS
330330
// Font
331331
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)defaultFontName, defaultFontSize, NULL);
332332
if (font == NULL) font = CTFontCreateWithName(CFSTR("Helvetica"), defaultFontSize, NULL);
333-
[string addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)font range:fullRange];
333+
// [string addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)font range:fullRange];
334334
NSMutableAttributedStringSetDefaultAttribute(string, (NSString *)kCTFontAttributeName, (__bridge id)font);
335335
CFRelease(font);
336336
return useFullColor;

0 commit comments

Comments
 (0)