I'm using Spritebuilder to develop a cocos2d application. I want to programmatically create a CCScrollView scroll
that loads a layer, Shop.ccb
that I created with SpriteBuilder. Shop.ccb
is just a CCNode that contains a few UI elements. Before, I used to just create all of it in Spritebuilder, but now I need to do it by adding scroll
to the parent container.
How I used to do it:
CCScrollView scroll
and CCNode Shop.ccb
Now, I want to do it programmatically, which is what I am having trouble with.
This is my code so far:
CCNode *shopNode = [CCBReader loadAsScene:@"Shop"];
[shopNode setContentSizeInPoints:(CGSizeMake(320, 1000))];
CCScrollView *scroll = [[CCScrollView alloc]initWithContentNode:shopNode];
[scroll setContentSizeInPoints:(CGSizeMake(320.0, 370.0))];
[scroll setHorizontalScrollEnabled:NO];
[scroll setPosition:(CGPointMake(0, 70))];
[scroll setScrollPosition:(CGPointMake(0, 370))];
[[CCDirector sharedDirector].runningScene addChild:scroll];
When I run the program, I cannot scroll. It does not let me scroll up or down, even though vertical scroll is NOT disabled. When I remove [scroll setContentSizeInPoints:(CGSizeMake(320.0, 370.0))];
, only then does it let me scroll up and down. Also, it isn't the correct size. It isn't confined to a 320x370 area, it takes up the entire screen. Any ideas as to what I am doing wrong here? Thank you.