Difference between revisions of "GSDP:GAM100/CProcessing/CP System GetDt()"
From Inside
< GSDP:GAM100 | CProcessing
>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...) |
(Possible origin or child content: https://github.com/DigiPen-Faculty/CProcessing/wiki/System#CP_System_GetDt) |
||
(2 intermediate revisions by one other user not shown) | |||
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== | ||
− | 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) | ||
{ | { | ||
− | // | + | // clear the background |
− | |||
− | |||
CP_Settings_Background(CP_Color_Create(200, 200, 200, 255)); | 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 }; | char buffer[16] = { 0 }; | ||
− | sprintf_s(buffer, _countof(buffer), "%. | + | sprintf_s(buffer, _countof(buffer), "%.2f", totalElapsedTime); |
CP_Font_DrawText(buffer, 200, 200); | CP_Font_DrawText(buffer, 200, 200); | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ==Related== | |
* [[GSDP:GAM100/CProcessing |Main Page ]] | * [[GSDP:GAM100/CProcessing |Main Page ]] |
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);
}