Difference between revisions of "GSDP:GAM100/CProcessing/Run()"

From Inside
Jump to: navigation, search
>D.hamilton
>Zachary.logsdon
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{GSDP:GAM100API.css}}
 +
= Run() =
 +
 
== Description ==
 
== Description ==
This function is what runs your program for you. When you write [[setup()]] and [[draw()]] functions in your work space, then you call Run with the names of those functions to loop your program.
+
This function is what starts the CProcessing engine. Before calling run(), [[GSDP:GAM100/CProcessing/SetNextGameState()|SetNextGameState()]] or [[GSDP:GAM100/CProcessing/SetNextGameStateForced()|SetNextGameStateForced()]] must be called to set the initial state of the program. Failing to do so will make the program end immediately.
 
 
 
 
Setup will be called exactly once at the beginning of the program. Draw will be called once per frame for the life of the program.
 
 
 
 
 
The [[setup()]] and [[draw()]] functions must take no parameters and return nothing.
 
  
 
== Example Usage ==
 
== Example Usage ==
<syntaxhighlight lang="c" line='line'>
+
<syntaxhighlight lang='c'>
void setup(void)
+
void init(void)
 
{
 
{
    /* Set the size of the window */
+
  /* Set the size of the window */
    size(500, 500);
+
  size(500, 500);
 
}
 
}
  
void draw(void)
+
void update(void)
 
{
 
{
    /* Set the background color to black every frame */
+
  /* Set the background color to black every frame */
    background(0, 0, 0, 255);
+
  background(color(0, 0, 0, 255));
  
    /* Draw a rectangle at the mouse position */
+
  /* Draw a rectangle at the mouse position */
    rect(mouseX, mouseY, 50, 50);
+
  rect(mouseX, mouseY, 50, 50);
 
}
 
}
  
int main(void)
+
CP_main
 
{
 
{
    /* Run the program */
+
  // Set the initial game state
    Run(setup, draw);     
+
  SetNextGameState(init, update, NULL);
 +
 
 +
  // Run the program
 +
  Run();     
 
}
 
}
  
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
  
 
=== See Also ===
 
=== See Also ===
* [[setup()]]
+
* [[GSDP:GAM100/CProcessing|Main Page]]
* [[draw()]]
+
* [[GSDP:GAM100/CProcessing/Run()|Run()]]
* [[size()]]
+
* [[GSDP:GAM100/CProcessing/CP_main|CP_main]]
* [[background()]]
+
* [[GSDP:GAM100/CProcessing/Terminate()|Terminate()]]
* [[rect()]]
+
* [[GSDP:GAM100/CProcessing/SetNextGameState()|SetNextGameState()]]
 +
* [[GSDP:GAM100/CProcessing/SetNextGameStateForced()|SetNextGameStateForced()]]

Latest revision as of 09:42, 20 October 2019

Run()

Description

This function is what starts the CProcessing engine. Before calling run(), SetNextGameState() or SetNextGameStateForced() must be called to set the initial state of the program. Failing to do so will make the program end immediately.

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

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>