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

From Inside
Jump to: navigation, search
>Justin.chambers
>Justin.chambers
Line 31: Line 31:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
====Related====
+
==Related==
  
 
* [[GSDP:GAM100/CProcessing      |Main Page          ]]
 
* [[GSDP:GAM100/CProcessing      |Main Page          ]]

Revision as of 16:53, 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:>