Skip to content

Commit 821add6

Browse files
committed
Merge branch 'v3.0' of github:cocos2d/cocos2d-iphone into v3.0
2 parents 9df89a1 + 8d2be43 commit 821add6

File tree

6 files changed

+97
-49
lines changed

6 files changed

+97
-49
lines changed

cocos2d-ui-tests/tests/CCRendererTest.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,36 @@ - (void)setupProgressNodeTest
340340
[timer repeatOnceWithInterval:interval];
341341
} delay:interval];
342342
}
343+
344+
{
345+
NSString *image = @"Tiles/05.png";
346+
CGPoint position = ccp(0.5, 3.0/8.0);
347+
348+
CCSprite *sprite = [CCSprite spriteWithImageNamed:image];
349+
sprite.positionType = CCPositionTypeNormalized;
350+
sprite.position = position;
351+
sprite.color = [CCColor grayColor];
352+
[self.contentNode addChild:sprite];
353+
354+
CCProgressNode *progress = [CCProgressNode progressWithSprite:[CCSprite spriteWithImageNamed:image]];
355+
progress.type = CCProgressNodeTypeBar;
356+
progress.midpoint = ccp(0.5, 0.5);
357+
progress.barChangeRate = ccp(1, 1);
358+
progress.positionType = CCPositionTypeNormalized;
359+
progress.position = position;
360+
progress.percentage = 50;
361+
[self.contentNode addChild:progress];
362+
363+
[self scheduleBlock:^(CCTimer *timer) {
364+
progress.sprite = [CCSprite spriteWithImageNamed:@"Tiles/06.png"];
365+
[timer repeatOnceWithInterval:1.0];
366+
} delay:0.5];
367+
368+
[self scheduleBlock:^(CCTimer *timer) {
369+
progress.sprite = [CCSprite spriteWithImageNamed:@"Tiles/05.png"];
370+
[timer repeatOnceWithInterval:1.0];
371+
} delay:1.0];
372+
}
343373
}
344374

345375
- (void)setupDrawNodeTest

cocos2d/CCParallaxNode.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,15 @@ -(void) addChild: (CCNode*) child z:(NSInteger)z parallaxRatio:(CGPoint)ratio po
9595

9696
-(void) removeChild:(CCNode*)node cleanup:(BOOL)cleanup
9797
{
98-
[_parallaxArray removeObject:node];
98+
for(NSUInteger i = 0; i < _parallaxArray.count; i++){
99+
CGPointObject *point = _parallaxArray[i];
100+
101+
if(point.child == node) {
102+
[_parallaxArray removeObjectAtIndex:i];
103+
break;
104+
}
105+
}
106+
99107
[super removeChild:node cleanup:cleanup];
100108
}
101109

cocos2d/CCProgressNode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ typedef NS_ENUM(NSUInteger, CCProgressNodeType) {
6666
CGPoint _midpoint;
6767
CGPoint _barChangeRate;
6868
BOOL _reverseDirection;
69+
70+
BOOL _dirtyVertexData;
71+
BOOL _needsUpdateProgress;
6972
}
7073

7174

cocos2d/CCProgressNode.m

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,20 @@ -(id) init
8282
-(id)initWithSprite:(CCSprite*) sprite
8383
{
8484
if(( self = [super init] )){
85+
_type = CCProgressNodeTypeRadial;
86+
_reverseDirection = NO;
8587
_percentage = 0.f;
8688
_vertexData = NULL;
8789
_vertexDataCount = 0;
90+
8891
self.anchorPoint = ccp(0.5f,0.5f);
89-
self.type = CCProgressNodeTypeRadial;
90-
self.reverseDirection = NO;
91-
self.midpoint = ccp(.5f, .5f);
92-
self.barChangeRate = ccp(1,1);
92+
self.midpoint = ccp(0.5f, 0.5f);
93+
self.barChangeRate = ccp(1, 1);
9394
self.sprite = sprite;
94-
95+
96+
_dirtyVertexData = NO;
97+
_needsUpdateProgress = YES;
98+
9599
// shader program
96100
self.shaderProgram = [[CCShaderCache sharedShaderCache] programForKey:kCCShader_PositionTextureColor];
97101
}
@@ -105,11 +109,14 @@ -(void)dealloc
105109
}
106110
}
107111

108-
-(void)setPercentage:(float) percentage
112+
-(void)setPercentage:(float)percentage
109113
{
110114
if(_percentage != percentage) {
111-
_percentage = clampf( percentage, 0, 100);
112-
[self updateProgress];
115+
_percentage = clampf(percentage, 0, 100);
116+
117+
// only flag update progress here, let the progress type handle
118+
// whether it needs to rebuild the vertex data
119+
_needsUpdateProgress = YES;
113120
}
114121
}
115122

@@ -119,27 +126,18 @@ -(void)setSprite:(CCSprite *)newSprite
119126
_sprite = newSprite;
120127
self.contentSize = _sprite.contentSize;
121128

122-
// Everytime we set a new sprite, we free the current vertex data
123-
if(_vertexData){
124-
free(_vertexData);
125-
_vertexData = NULL;
126-
_vertexDataCount = 0;
127-
}
129+
_dirtyVertexData = YES;
130+
_needsUpdateProgress = YES;
128131
}
129132
}
130133

131134
-(void)setType:(CCProgressNodeType)newType
132135
{
133136
if (newType != _type) {
134-
135-
// release all previous information
136-
if(_vertexData){
137-
free(_vertexData);
138-
_vertexData = NULL;
139-
_vertexDataCount = 0;
140-
}
141137
_type = newType;
142-
[self updateProgress];
138+
139+
_dirtyVertexData = YES;
140+
_needsUpdateProgress = YES;
143141
}
144142
}
145143

@@ -148,12 +146,8 @@ -(void)setReverseDirection:(BOOL)reverse
148146
if( _reverseDirection != reverse ) {
149147
_reverseDirection = reverse;
150148

151-
// release all previous information
152-
if(_vertexData){
153-
free(_vertexData);
154-
_vertexData = NULL;
155-
_vertexDataCount = 0;
156-
}
149+
_dirtyVertexData = YES;
150+
_needsUpdateProgress = YES;
157151
}
158152
}
159153

@@ -225,15 +219,25 @@ -(void)updateColor
225219

226220
-(void)updateProgress
227221
{
222+
if (_dirtyVertexData){
223+
// remove the vertex data if the type, direction, or sprite have changed
224+
if (_vertexData) {
225+
free(_vertexData);
226+
_vertexData = NULL;
227+
_vertexDataCount = 0;
228+
}
229+
_dirtyVertexData = NO;
230+
}
231+
228232
switch (_type) {
229233
case CCProgressNodeTypeRadial:
230234
[self updateRadial];
231-
break;
235+
return;
232236
case CCProgressNodeTypeBar:
233237
[self updateBar];
234-
break;
238+
return;
235239
default:
236-
break;
240+
return;
237241
}
238242
}
239243

@@ -503,7 +507,12 @@ -(CGPoint)boundaryTexCoord:(char)index
503507

504508
-(void) draw
505509
{
506-
if( ! _vertexData || ! _sprite)
510+
if (_needsUpdateProgress) {
511+
[self updateProgress];
512+
_needsUpdateProgress = NO;
513+
}
514+
515+
if (!_vertexData || !_sprite)
507516
return;
508517

509518
CC_NODE_DRAW_SETUP();

cocos2d/CCResponderManager.m

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,29 @@ - (void)buildResponderList
103103
_dirty = NO;
104104
}
105105

106-
-( void )buildResponderList:(CCNode *)node
106+
- (void)buildResponderList:(CCNode *)node
107107
{
108-
BOOL nodeAdded = NO;
109-
110108
// dont add invisible nodes
111109
if (!node.visible) return;
112110

113-
if ((node.children) && (node.children.count > 0))
111+
BOOL shouldAddNode = node.isUserInteractionEnabled;
112+
113+
if (node.children.count)
114114
{
115-
// scan through children, and build responderlist
115+
// scan through children, and build responder list
116116
for (CCNode *child in node.children)
117117
{
118-
if ((child.zOrder >= 0) && (!nodeAdded) && (node.isUserInteractionEnabled))
118+
if (shouldAddNode && child.zOrder >= 0)
119119
{
120120
[self addResponder:node];
121-
nodeAdded = YES;
121+
shouldAddNode = NO;
122122
}
123123
[self buildResponderList:child];
124124
}
125125
}
126-
else
127-
{
128-
// only add self
129-
if (node.isUserInteractionEnabled) [self addResponder:node];
130-
}
126+
127+
// if eligible, add the current node to the responder list
128+
if (shouldAddNode) [self addResponder:node];
131129
}
132130

133131
// -----------------------------------------------------------------

cocos2d/CCTexture.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ - (id) initWithCGImage:(CGImageRef)cgImage contentScale:(CGFloat)contentScale
460460
// Repack the pixel data into the right format
461461

462462
if(pixelFormat == CCTexturePixelFormat_RGB565) {
463-
//Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGGBBBBB"
463+
//Convert "RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGGBBBBB"
464464
tempData = malloc(textureHeight * textureWidth * 2);
465465
inPixel32 = (unsigned int*)data;
466466
outPixel16 = (unsigned short*)tempData;
@@ -472,7 +472,7 @@ - (id) initWithCGImage:(CGImageRef)cgImage contentScale:(CGFloat)contentScale
472472
}
473473

474474
else if(pixelFormat == CCTexturePixelFormat_RGB888) {
475-
//Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRRRRGGGGGGGGBBBBBBB"
475+
//Convert "RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRRRRGGGGGGGGBBBBBBB"
476476
tempData = malloc(textureHeight * textureWidth * 3);
477477
char *inData = (char*)data;
478478
char *outData = (char*)tempData;
@@ -488,7 +488,7 @@ - (id) initWithCGImage:(CGImageRef)cgImage contentScale:(CGFloat)contentScale
488488
}
489489

490490
else if (pixelFormat == CCTexturePixelFormat_RGBA4444) {
491-
//Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRGGGGBBBBAAAA"
491+
//Convert "RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRGGGGBBBBAAAA"
492492
tempData = malloc(textureHeight * textureWidth * 2);
493493
inPixel32 = (unsigned int*)data;
494494
outPixel16 = (unsigned short*)tempData;
@@ -505,7 +505,7 @@ - (id) initWithCGImage:(CGImageRef)cgImage contentScale:(CGFloat)contentScale
505505

506506
}
507507
else if (pixelFormat == CCTexturePixelFormat_RGB5A1) {
508-
//Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGBBBBBA"
508+
//Convert "RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGBBBBBA"
509509
/*
510510
Here was a bug.
511511
When you convert RGBA8888 texture to RGB5A1 texture and then render it on black background, you'll see a "ghost" image as if the texture is still RGBA8888.

0 commit comments

Comments
 (0)