GSDP:GAM100/CProcessing/CP System SetNextGameStateForced()
< GSDP:GAM100 | CProcessing
CP_System_SetNextGameStateForced()
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_SetNextGameStateForced() allows you to reset your current game state, while CP_System_SetNextGameState() with the current game state will not.
Parameters
CP_System_SetNextGameStateForced(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
// Horizontal position of the square
float x_pos;
void init()
{
// Start the square at the left of the screen
x_pos = 0;
// Set the square to draw yellow
CP_Settings_Fill(CP_Color_Create(255, 255, 0, 255));
}
void update()
{
// Set background to black
CP_Settings_Background(CP_Color_Create(0, 0, 0, 255));
// Draw the square
CP_Graphics_DrawRect(x_pos, (float)CP_System_GetCanvasHeight() / 2.0f, 100, 100);
x_pos += 2;
// If space pressed, reset the state
if (CP_Input_KeyTriggered(KEY_SPACE))
CP_System_SetNextGameStateForced(init, update, NULL);
}
int main(void)
{
// Set the initial game state
CP_System_SetNextGameState(init, update, NULL);
// Run the program
CP_System_Run();
}