GSDP:GAM100/CProcessing/CP System SetNextGameState()
From Inside
< GSDP:GAM100 | CProcessing
CP_System_SetNextGameState()
Description
This sets the next state for the program to enter. This will call the shutdown function of the current state if own exists. Calling CP_System_SetNextGameState() on the same state you are currently in will have no effect, but calling CP_System_SetNextGameStateForced() will restart the current state.
Parameters
CP_System_SetNextGameState(FunctionPtr init, FunctionPtr update, FunctionPtr shutdown)
- init - (FunctionPtr) The name of the function called once when the state first begins. This can be NULL if no initialization is needed for your state.
- update - (FunctionPtr) The name of the function called every frame to update the state.
- shutdown - (FunctionPtr) The name of the function called when you leave a state. This occurs when you call CP_System_SetNextGameState or CP_System_SetNextGameStateForced() to change states. This can be NULL if no cleanup is needed for your state.
Example Usage
void init(void)
{
/* Set the size of the window */
CP_System_Size(500, 500);
}
void update(void)
{
/* Set the background color to black every frame */
CP_Settings_Background(CP_Color_Create(0, 0, 0, 255));
/* Draw a rectangle at the mouse position */
CP_Graphics_DrawRect(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 50, 50);
}
int main(void)
{
// Set the initial game state
CP_System_SetNextGameState(init, update, NULL);
// Run the program
CP_System_Run();
}