Difference between revisions of "GSDP:GAM100/CProcessing/CP System GetDt()"

From Inside
Jump to: navigation, search
>Justin.chambers
(New page: {{GSDP:GAM100API.css}} =CP_System_GetDt()= ==Description== Returns the elapsed time from the last frame. ==Example== <syntaxhighlight lang='c'> void update(void) { // print the curr...)
 
>Justin.chambers
Line 3: Line 3:
  
 
==Description==
 
==Description==
Returns the elapsed time from the last frame.
+
Returns the elapsed time from the last frame.  This is very important when making frame independent calculations such as movement or physics.
  
 
==Example==
 
==Example==
 
<syntaxhighlight lang='c'>
 
<syntaxhighlight lang='c'>
 +
void init(void)
 +
{
 +
    // initialize settings
 +
    CP_Settings_TextSize(150);
 +
    CP_Settings_TextAlignment(CP_TEXT_ALIGN_H_CENTER, CP_TEXT_ALIGN_V_MIDDLE);
 +
    CP_Settings_Fill(CP_Color_Create(100, 20, 100, 255));
 +
}
 +
 
void update(void)  
 
void update(void)  
 
{
 
{
     // print the current frame rate to the center of the window
+
     // clear the background
    CP_Settings_TextSize(200);
 
    CP_Settings_TextAlignment(CP_TEXT_ALIGN_H_CENTER, CP_TEXT_ALIGN_V_MIDDLE);
 
 
     CP_Settings_Background(CP_Color_Create(200, 200, 200, 255));
 
     CP_Settings_Background(CP_Color_Create(200, 200, 200, 255));
     CP_Settings_Fill(CP_Color_Create(100, 20, 100, 255));
+
 
      
+
    // get dt and then print total elapsed time
     float currentFrameRate = CP_System_GetFrameRate();
+
     float currentElapsedTime = CP_System_GetDt();
 +
     static float totalElapsedTime = 0;
 +
     totalElapsedTime += currentElapsedTime;
 
      
 
      
 
     char buffer[16] = { 0 };
 
     char buffer[16] = { 0 };
     sprintf_s(buffer, _countof(buffer), "%.1f", currentFrameRate );
+
     sprintf_s(buffer, _countof(buffer), "%.2f", totalElapsedTime);
 
     CP_Font_DrawText(buffer, 200, 200);
 
     CP_Font_DrawText(buffer, 200, 200);
 
}
 
}

Revision as of 16:37, 25 July 2020

CP_System_GetDt()

Description

Returns the elapsed time from the last frame. This is very important when making frame independent calculations such as movement or physics.

Example

void init(void)
{
    // initialize settings
    CP_Settings_TextSize(150);
    CP_Settings_TextAlignment(CP_TEXT_ALIGN_H_CENTER, CP_TEXT_ALIGN_V_MIDDLE);
    CP_Settings_Fill(CP_Color_Create(100, 20, 100, 255));
}

void update(void) 
{
    // clear the background
    CP_Settings_Background(CP_Color_Create(200, 200, 200, 255));

    // get dt and then print total elapsed time
    float currentElapsedTime = CP_System_GetDt();
    static float totalElapsedTime = 0;
    totalElapsedTime += currentElapsedTime;
    
    char buffer[16] = { 0 };
    sprintf_s(buffer, _countof(buffer), "%.2f", totalElapsedTime);
    CP_Font_DrawText(buffer, 200, 200);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>