我想让CCTableView使用cocos2d 3.0,但我真的不知道从哪里开始.有没有人有一个很好的教程或3.0的任何东西?我看到有一些旧版本的cocos2d但没有3.0版本.任何帮助表示赞赏!谢谢!
解决方法
这是一个简短的样本.我建议你自己尝试编写一些代码,然后发布你遇到的问题.它绝对可以让您更轻松地回答问题.如果需要,您还可以创建自己的CCTableViewCell子类.
头文件,SampleTableView.h
#import "cocos2d.h" #import "cocos2d-ui.h" @interface SampleTableView : CCNode <CCTableViewDataSource> @end
源文件: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);
以下是它的样子截图:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。