Skip to content

Commit 163a905

Browse files
author
Thayer J Andrews
committed
CCEffectNode - More parent relative sizing fixes
Keep track of the last allocated content size and compare this to the current content size. If the two are different, destroy and reallocate the associated texture and FBO. This fixes cases where the effect node's size is parent relative (and does not change) but the parent's size does change.
1 parent e4a82a4 commit 163a905

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

cocos2d/CCEffectNode.m

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ @interface CCEffectNode()
3232
{
3333
CCEffect *_effect;
3434
CCEffectRenderer *_effectRenderer;
35+
CGSize _allocatedSize;
3536
}
3637

3738
@end
@@ -48,6 +49,7 @@ -(id)initWithWidth:(int)width height:(int)height
4849
{
4950
if((self = [super initWithWidth:width height:height pixelFormat:CCTexturePixelFormat_Default])) {
5051
_effectRenderer = [[CCEffectRenderer alloc] init];
52+
_allocatedSize = CGSizeMake(0.0f, 0.0f);
5153
}
5254
return self;
5355
}
@@ -72,14 +74,20 @@ -(void)setEffect:(CCEffect *)effect
7274

7375
-(void)create
7476
{
75-
CGSize pointSize = self.contentSizeInPoints;
76-
CGSize pixelSize = CGSizeMake(pointSize.width * _contentScale, pointSize.height * _contentScale);
77+
_allocatedSize = self.contentSizeInPoints;
78+
CGSize pixelSize = CGSizeMake(_allocatedSize.width * _contentScale, _allocatedSize.height * _contentScale);
7779
[self createTextureAndFboWithPixelSize:pixelSize];
7880

79-
CGRect rect = CGRectMake(0, 0, pointSize.width, pointSize.height);
81+
CGRect rect = CGRectMake(0, 0, _allocatedSize.width, _allocatedSize.height);
8082
[_sprite setTextureRect:rect];
8183

82-
_projection = GLKMatrix4MakeOrtho(0.0f, pointSize.width, 0.0f, pointSize.height, -1024.0f, 1024.0f);
84+
_projection = GLKMatrix4MakeOrtho(0.0f, _allocatedSize.width, 0.0f, _allocatedSize.height, -1024.0f, 1024.0f);
85+
}
86+
87+
-(void)destroy
88+
{
89+
[super destroy];
90+
_allocatedSize = CGSizeMake(0.0f, 0.0f);
8391
}
8492

8593
-(void)begin
@@ -123,9 +131,11 @@ -(void)visit:(CCRenderer *)renderer parentTransform:(const GLKMatrix4 *)parentTr
123131
// Don't call visit on its children
124132
if(!_visible) return;
125133

126-
if(_contentSizeChanged)
134+
CGSize pointSize = self.contentSizeInPoints;
135+
if (!CGSizeEqualToSize(pointSize, _allocatedSize))
127136
{
128137
[self destroy];
138+
[self contentSizeChanged];
129139
_contentSizeChanged = NO;
130140
}
131141

@@ -224,10 +234,4 @@ - (void)updateShaderUniformsFromEffect
224234
[_shaderUniforms addEntriesFromDictionary:_effect.shaderUniforms];
225235
}
226236

227-
- (void)setContentSizeType:(CCSizeType)contentSizeType
228-
{
229-
[super setContentSizeType:contentSizeType];
230-
_contentSizeChanged = YES;
231-
}
232-
233237
@end

cocos2d/CCNode_Private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,6 @@ CGAffineTransform CGAffineTransformMakeRigid(CGPoint translate, CGFloat radians)
107107
*/
108108
-(void) detachChild:(CCNode *)child cleanup:(BOOL)doCleanup;
109109

110+
- (void) contentSizeChanged;
111+
110112
@end

0 commit comments

Comments
 (0)