Difference between revisions of "Gb.update"

From Gamebuino Wiki
Jump to: navigation, search
(Created page with "Updates the gamebuino (the display, the sound, the auto backlight... everything). returns true when it's time to render a new frame.")
 
Line 1: Line 1:
Updates the gamebuino (the display, the sound, the auto backlight... everything).
+
{{DISPLAYTITLE:gb.update}}
returns true when it's time to render a new frame.
+
__NOTOC__
 +
= Description =
 +
Returns true and updates everything (display, sound, batter monitor, etc.) at a fixed frequency (20 times per second by default).
 +
 
 +
It should be used in a specific conditional structure, see "Syntax".
 +
 
 +
= Syntax =
 +
<pre>
 +
while(1){
 +
  if(gb.update()){
 +
    //your game here
 +
  }
 +
}
 +
</pre>
 +
 
 +
= Parameters =
 +
none
 +
 
 +
= Returns =
 +
boolean: return true if enough time has elapsed since the last frame (20 frames per second = 50ms per frame).
 +
 
 +
= Example =
 +
<pre>
 +
#include <SPI.h>
 +
#include <Gamebuino.h>
 +
Gamebuino gb;
 +
 
 +
void setup(){
 +
  gb.begin(F("Example game"));
 +
 
 +
  while(1){ //loops forever
 +
    if(gb.update()){ //update everything
 +
   
 +
      //put your game here. I will run at a fixed frequency (20 times per second by default)
 +
 
 +
      if(gb.buttons.pressed(BTN_C) //break out of the loop if C is pressed
 +
        break;
 +
    }
 +
  }
 +
}
 +
 
 +
void loop(){
 +
 
 +
}
 +
</pre>
 +
 
 +
= See also =
 +
*[[gb.begin]]
 +
*[[gb.setFrameRate]]

Revision as of 2014-05-14T21:25:16


Description

Returns true and updates everything (display, sound, batter monitor, etc.) at a fixed frequency (20 times per second by default).

It should be used in a specific conditional structure, see "Syntax".

Syntax

while(1){
  if(gb.update()){
    //your game here
  }
}

Parameters

none

Returns

boolean: return true if enough time has elapsed since the last frame (20 frames per second = 50ms per frame).

Example

#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

void setup(){
  gb.begin(F("Example game"));

  while(1){ //loops forever
    if(gb.update()){ //update everything
    
      //put your game here. I will run at a fixed frequency (20 times per second by default)

      if(gb.buttons.pressed(BTN_C) //break out of the loop if C is pressed
        break;
    }
  }
}

void loop(){

}

See also