Skip to content

Commit 4915f17

Browse files
author
Thayer J Andrews
committed
CCEffectNode - Fix effect node resizing
Because content size changes are handled in render texture's visit method and because effect node overrides visit, changes to effect node content size were not being applied.
1 parent 887ff23 commit 4915f17

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,60 @@ -(void)setupEffectNodeSizeTypeTest
785785
}
786786
}
787787

788+
-(void)setupEffectNodeResizeTest
789+
{
790+
NSArray *subTitles = @[
791+
@"Effect Node Resize Test\nSmall transparent blue node with grossini",
792+
@"Effect Node Resize Test\nMedium transparent blue node with grossini",
793+
@"Effect Node Resize Test\nBig transparent blue node with grossini"
794+
];
795+
796+
self.subTitle = subTitles[0];
797+
798+
CCSprite *background = [CCSprite spriteWithImageNamed:@"Images/gridBackground.png"];
799+
background.positionType = CCPositionTypeNormalized;
800+
background.position = ccp(0.5f, 0.5f);
801+
[self.contentNode addChild:background];
802+
803+
CCEffectNode* effectNode = [[CCEffectNode alloc] init];
804+
effectNode.clearFlags = GL_COLOR_BUFFER_BIT;
805+
effectNode.clearColor = [CCColor colorWithRed:0.5f green:0.0f blue:0.0f alpha:0.5f];
806+
effectNode.contentSizeType = CCSizeTypeNormalized;
807+
effectNode.contentSize = CGSizeMake(0.25f, 0.25f);
808+
effectNode.anchorPoint = ccp(0.5f, 0.5f);
809+
effectNode.positionType = CCPositionTypeNormalized;
810+
effectNode.position = ccp(0.5f, 0.5f);
811+
812+
CCEffectHue *effect = [CCEffectHue effectWithHue:-120.0f];
813+
effectNode.effect = effect;
814+
815+
[self.contentNode addChild:effectNode];
816+
817+
818+
CCSprite *sprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
819+
sprite.anchorPoint = ccp(0.5, 0.5);
820+
sprite.positionType = CCPositionTypeNormalized;
821+
sprite.position = ccp(0.5f, 0.5f);
822+
[effectNode addChild:sprite];
823+
824+
825+
__weak CCEffectsTest *weakSelf = self;
826+
__block NSUInteger callCount = 0;
827+
CCActionCallBlock *blockAction = [CCActionCallBlock actionWithBlock:^{
828+
callCount = (callCount + 1) % 3;
829+
830+
float nodeSize = 0.25f + 0.25f * callCount;
831+
effectNode.contentSize = CGSizeMake(nodeSize, nodeSize);
832+
833+
weakSelf.subTitle = subTitles[callCount];
834+
}];
835+
[effectNode runAction:[CCActionRepeatForever actionWithAction:[CCActionSequence actions:
836+
[CCActionDelay actionWithDuration:1.0f],
837+
blockAction,
838+
nil
839+
]]];
840+
}
841+
788842
-(void)setupEffectNodeChildPositioningTest
789843
{
790844
self.subTitle = @"Effect Node Child Positioning Test\nBig transparent purple quad and small opaque green quad (both with grossini).\n";

cocos2d/CCEffectNode.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ -(void)visit:(CCRenderer *)renderer parentTransform:(const GLKMatrix4 *)parentTr
122122
// override visit.
123123
// Don't call visit on its children
124124
if(!_visible) return;
125+
126+
if(_contentSizeChanged)
127+
{
128+
[self destroy];
129+
_contentSizeChanged = NO;
130+
}
125131

126132
GLKMatrix4 transform = [self transform:parentTransform];
127133

0 commit comments

Comments
 (0)