cocos2d-iphone – 带有cocos2d 3.0的CCTableView
发布时间:2020-12-14 18:57:49 所属栏目:百科 来源:网络整理
导读:我想让CCTableView使用cocos2d 3.0,但我真的不知道从哪里开始.有没有人有一个很好的教程或3.0的任何东西?我看到有一些旧版本的cocos2d但没有3.0版本.任何帮助表示赞赏!谢谢! 解决方法 这是一个简短的样本.我建议你自己尝试编写一些代码,然后发布你遇到的
我想让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); 以下是它的样子截图: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |