Difference between revisions of "GSDP:GAM100/CProcessing/CP System GetDt()"
From Inside
< GSDP:GAM100 | CProcessing
>Justin.chambers |
(Possible origin or child content: https://github.com/DigiPen-Faculty/CProcessing/wiki/System#CP_System_GetDt) |
||
Line 1: | Line 1: | ||
{{GSDP:GAM100API.css}} | {{GSDP:GAM100API.css}} | ||
=CP_System_GetDt()= | =CP_System_GetDt()= | ||
+ | Possible origin or child content: https://github.com/DigiPen-Faculty/CProcessing/wiki/System#CP_System_GetDt | ||
==Description== | ==Description== |
Latest revision as of 20:45, 15 February 2023
CP_System_GetDt()
Possible origin or child content: https://github.com/DigiPen-Faculty/CProcessing/wiki/System#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);
}