September 2018
Intermediate to advanced
328 pages
9h 10m
English
The final section of code displays the score at the bottom of the game window:
void Board::displayScore(SDL_Renderer *renderer, TTF_Font *font) { std::stringstream message; message << "ROWS: " << currentScore_; SDL_Color white = { 255, 255, 255 }; SDL_Surface *surface = TTF_RenderText_Blended( font, message.str().c_str(), white); SDL_Texture *texture = SDL_CreateTextureFromSurface( renderer, surface); SDL_Rect messageRect{ 20, BoardHeight + 15, surface->w, surface->h }; SDL_FreeSurface(surface); SDL_RenderCopy(renderer, texture, nullptr, &messageRect); SDL_DestroyTexture(texture);}
The displayScore() function uses the SDL2_ttf library to display the current score at the bottom of the window (underneath the board). ...
Read now
Unlock full access