CCScrollView doesn't show ContentNode

76 Views Asked by At

I succeeded to show a contentNode on a scrollView published from SpriteBuilder. But couldn't show it on a scrollView made programatically.

I just put these codes on didLordFromCCB MainScene.m. I did nothing with the SpriteBuilder project.

CCNodeColor* base = [CCNodeColor nodeWithColor:[CCColor blueColor] width:760 height:200];
base.position = ccp(30, 200);
CCNodeColor* color0 = [CCNodeColor nodeWithColor:[CCColor magentaColor] width:100 height:100];
color0.position= ccp(0, 0);
[base addChild:color0];

CCNodeColor* color1 = [CCNodeColor nodeWithColor:[CCColor magentaColor] width:100 height:100];
color1.position= ccp(660, 0);
[base addChild:color1];

CCNodeColor* color2 = [CCNodeColor nodeWithColor:[CCColor magentaColor] width:100 height:100];
color2.position= ccp(330, 100);
[base addChild:color2];

CCScrollView* sv = [[CCScrollView alloc]initWithContentNode:base];
[self addChild:sv];

sv.horizontalScrollEnabled = YES;
sv.contentSize = CGSizeMake(260, 200);
[sv setPositionInPoints:ccp(30, 200)];
1

There are 1 best solutions below

1
On

I know that I'm late but maybe I still can help someone:

Inside of CCScrollView initialisation I found this line:

self.contentSizeType = CCSizeTypeNormalized;

So you just need to set contentSizeType back to "CCSizeTypePoints":

sv.contentSize = CCSizeTypePoints;
sv.contentSize = CGSizeMake(260, 200);

Hope this helps! I signed up a few mins ago just to leave this comment :)