Please Login First
×
Create a new article
Write your page title here:
We currently have 321 articles on Inside. Type your article name above or click on one of the titles below and start writing!



    Inside

    GSDP:GAM100/CProcessing/SetNextGameState()

    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 SetNextGameState() on the same state you are currently in will have no effect, but calling SetNextGameStateForced() will restart the current state.

    Parameters

    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 SetNextGameState or 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 */
      size(500, 500);
    }
    
    void update(void)
    {
      /* Set the background color to black every frame */
      background(color(0, 0, 0, 255));
    
      /* Draw a rectangle at the mouse position */
      rect(mouseX, mouseY, 50, 50);
    }
    
    CP_main
    {
      // Set the initial game state
      SetNextGameState(init, update, NULL);
    
      // Run the program
      Run();    
    }
    

    See Also