Lazy SDL Tutorial Translation----Lesson Timing

Source: Internet
Author: User
Tags time in milliseconds

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.