3D Game Builder SDK

SDK Functions

gameTick( void )


Get a value that is in sync with time.

Call this function once per frame only.


float gameTick( void )

return value

= a value in sync with time


This function allows you to sync your game with time.

Not all computers run at the same speed. As a result, your game may run faster on a faster computer, and slower on a slower computer.

For example, if you have a ball bouncing around the screen, it may appear faster or slower depending on the performance of the host computer.

You can ensure that the ball always appears to move at the same speed if you multiply the movement by a value in sync with time during each frame.

Call this function once per frame only.

For Example

#include "3dgamebuilder.h"

// draw ball
void drawBall( float x, float y, float z, float width, float height )
	float	w2, h2;

	// get half size so we can draw ball from center
	w2 = width  * 0.5f;
	h2 = height * 0.5f;

	// copy matrix
		// move into position
		glTranslatef( x, y, z );
		// draw ball (as a quad)
			glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
			glVertex2f( -w2, -h2 );
			glVertex2f( -w2,  h2 );
			glVertex2f(  w2, -h2 );
			glVertex2f(  w2,  h2 );

	// done with matrix

// exported game function
DLL_EXPORT int gameLoop(void)
	float posx  = 0.0f;
	float posy  = 0.0f;

	float stepx = 0.03f;
	float stepy = 0.02f;

	float tick;

	// reset

	// game loop
		// read the controller

		// start drawing frame
		// reset matrix
		glMatrixMode( GL_PROJECTION );
		// reset matrix
		glMatrixMode( GL_MODELVIEW );

		// draw ball
		drawBall( posx, posy, 0.0f, 0.03f, 0.1f );

		// move ball at a speed associated with time
		tick = gameTick() * 30.0f;
		posx += stepx * tick;
		posy += stepy * tick;

		// bounce off right side
		if (posx > 0.985f) {
			posx = 0.985f - (posx - 0.985f);
			stepx = -(stepx);
			gameMessage( "bounce off right side" );

		// bounce off left side
		if (posx < -0.985f) {
			posx = -0.985f - (posx + 0.985f);
			stepx = -(stepx);
			gameMessage( "bounce off left side" );

		// bounce off top side
		if (posy > 0.95f) {
			posy = 0.95f - (posy - 0.95f);
			stepy = -(stepy);
			gameMessage( "bounce off top side" );

		// bounce off bottom side
		if (posy < -0.95f) {
			posy = -0.95f - (posy + 0.95f);
			stepy = -(stepy);
			gameMessage( "bounce off bottom side" );

		// end of drawing

	return 0;

See Also

(no related functions)

Go Back

SDK Functions