Difference between revisions of "Gb.frameCount"

From Gamebuino Wiki
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:gb.frameCount}} __NOTOC__ = Description = This variable is incremented each time gb.update() is called, so it represents the number of frames rendered since the...")
 
m (Example)
Line 20: Line 20:
  
 
void setup(){
 
void setup(){
   gb.begin(F("My first game"));
+
   gb.begin(F("Example game"));
  gb.popup(F("Let's go!"), 30);
 
 
}
 
}
  

Revision as of 2014-05-15T08:09:14


Description

This variable is incremented each time gb.update() is called, so it represents the number of frames rendered since the program began running. It should be preferred over millis() to measure time. It can be used for periodic event timing (like an animated bitmap) using modulo.

Syntax

gb.frameCount

Parameters

none

Returns

Number of frames rendered since the program began running.

Example

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

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

void loop(){
  if(gb.update()){

    int count = gb.frameCount;
    gb.display.println(count);

    if((count%5) < 2){ //true for 2 frames once every 5 frames
      gb.display.println(F("BLINK"));
    }

  }
}

See also