Time for action – displaying highscores with CCTableView
Tables are great for displaying data. We are going to use a table control provided by Cocos2D to display a list of the highest scored points by our players. The table will contain a list of player names and their scores.
Since we are not prompting for the player's name just yet, we are going to display dummy data, and in the next section, we are going to replace it with real highscores.
Let's start:
- Open the
HighscoresScene.h
file and import thecocos2d-ui.h
header:#import "cocos2d-ui.h"
- Then, make the
HighscoresScene
class conform toCCTableViewDataSource
:@interface HighscoresScene: CCScene<CCTableViewDataSource>
- After that, switch to the
HighscoresScene.m
file and define the constants of the row height and font properties:#define kHighscoreRowHeight 32 #define kHighscoreFontName @"Helvetica" #define kHighscoreFontSize 12
- Scroll down and add the
addHighscoresTable
method as follows:-(void)addHighscoresTable...