Difference between revisions of "Gb.frameCount"

From Gamebuino Wiki
Jump to: navigation, search
m (Returns: added type)
(Changed title depth)
Line 1: Line 1:
 
{{DISPLAYTITLE:gb.frameCount}}
 
{{DISPLAYTITLE:gb.frameCount}}
 
__NOTOC__
 
__NOTOC__
= Description =
+
== 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.
 
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 =
+
== Syntax ==
 
<pre>int count = gb.frameCount;</pre>
 
<pre>int count = gb.frameCount;</pre>
  
= Parameters =
+
== Parameters ==
 
none
 
none
  
= Returns =
+
== Returns ==
 
Number of frames rendered since the program began running (''unsigned long'').
 
Number of frames rendered since the program began running (''unsigned long'').
  
= Example =
+
== Example ==
 
<pre>
 
<pre>
 
#include <SPI.h>
 
#include <SPI.h>
Line 37: Line 37:
 
</pre>
 
</pre>
  
= See also =
+
== See also ==
 
*[[gb.update]]
 
*[[gb.update]]
 
*[http://arduino.cc/en/Reference/modulo Modulo (Arduino)]
 
*[http://arduino.cc/en/Reference/modulo Modulo (Arduino)]

Revision as of 2014-05-18T09:57:43


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

int count = gb.frameCount;

Parameters

none

Returns

Number of frames rendered since the program began running (unsigned long).

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