Original: http://lazyfoo.net/tutorials/SDL/22_timing/index.php
Timing
Timing
Last Updated 3/10/14
Another important part of any sort of gaming API are the ability to handle time. In this tutorial we'll make a timer we can restart.
Another important part of any game API is the ability to handle time parameters. In this tutorial, we will write a timer that can be restarted.
Using SDL, Sdl_image, Sdl_ttf, Standard IO, strings, and string Streams#include <SDL.h> #include <SDL_IMAGE.H&G T, #include <SDL_ttf.h> #include <stdio.h> #include <string> #include <sstream>
For this tutorial we'll be using string streams and has to include the Sstream header which should come R C + + compiler.
In this tutorial, you will use string streams and include the stream header file, and your C + + compiler should have this header file.
bool Loadmedia () {//loading Success flag bool success = TRUE; Open the font gfont = Ttf_openfont ("22_timing/lazy.ttf", 28); if (Gfont = = NULL) {printf ("Failed to load lazy font! Sdl_ttf Error:%s\n ", Ttf_geterror ()); Success = false; } else {//set text color as black sdl_color TextColor = {0, 0, 0, 255}; Load prompt Texture if (!gprompttexttexture.loadfromrenderedtext ("Press Enter to Reset Start time.", TextColor) {printf ("Unable to render prompt texture!\n"); Success = false; }} return success;}
As mentioned in the and you want to minimize the amount of times you render text. We'll have a texture to prompt input and a texture to display the current time in milliseconds. The time texture changes every frame so we had to render this every frame, but the prompt texture doesn ' t change so we CA n render it once in the file loading function.
As mentioned in font rendering tutorial, reduce the time required for text rendering. We use a texture to show the input information and a texture to display the time (MS). Time texture changes in every frame, so you have to render each frame. But prompt texture does not change, so it can be rendered only once in the function that loads the file.
Lazy SDL Tutorial Translation----Lesson Timing