CCTableView with cocos2d 3.0

I am trying to get CCTableView to work with cocos2d 3.0, but I really don't know where to start. Does anyone have a good tutorial or anything else for 3.0? I see that there are several for older versions of cocos2d, but nothing for 3.0. Any help is appreciated! Thank!

+4
source share
2 answers

Here is a short sample. I recommend just trying to write some code yourself and then post what problems you have with it. This definitely makes answering questions easier. You can also create your own subclass CCTableViewCellif you wish.

Header File, SampleTableView.h

#import "cocos2d.h"
#import "cocos2d-ui.h"

@interface SampleTableView : CCNode <CCTableViewDataSource>
@end

Source file: SampleTableView.m

float const kNumberOfRows = 30.0f;

@implementation SampleTableView

- (instancetype)init
{
    self = [super init];
    if (self) {
        CCTableView* table = [CCTableView node];
        table.dataSource = self; // make our class the data source
        table.block = ^(CCTableView* table) {
            NSLog(@"Cell %d was pressed", (int) table.selectedRow);
        };
        [self addChild:table];
    }
    return self;
}

- (CCTableViewCell*) tableView:(CCTableView*)tableView nodeForRowAtIndex:(NSUInteger) index {
    CCTableViewCell* cell = [CCTableViewCell node];
    cell.contentSizeType = CCSizeTypeMake(CCSizeUnitNormalized, CCSizeUnitUIPoints);
    cell.contentSize = CGSizeMake(1.0f, 32.0f);
    float colorFactor = (index / kNumberOfRows);
    // Just a sample node that changes color with each index value
    CCNodeColor* colorNode = [CCNodeColor nodeWithColor:[CCColor colorWithRed:colorFactor green:(1.0f - colorFactor) blue:(0.2f + 0.5 * colorFactor) ] width:100.0f height:18.0f];
    [cell addChild:colorNode];
    return cell;
}

- (NSUInteger) tableViewNumberOfRows:(CCTableView*) tableView {
    return kNumberOfRows; // just a demo
}

:

SampleTableView* table = [SampleTableView node];
table.contentSizeType = CCSizeTypeNormalized;
table.contentSize = CGSizeMake(1.0, 1.0);

, : Samplescreenshot

+5

cocos2d-tests-ios.xcodeproj cocos2d. , cocos2d, CCTableView.

https://github.com/cocos2d/cocos2d-iphone

  • git cocos2d.
  • cocos2d-tests-ios.xcodeproj / cocos2d-tests-ios.
0

Source: https://habr.com/ru/post/1529102/


All Articles