Timers

Blitz3D Forums/Blitz3D Programming/Timers

Zach3D(Posted 2006) [#1]
I don't really understand timers yet, could someone show me an example code that makes a Cube move 1 X every 5 seconds using a timer, thanks.


Ross C(Posted 2006) [#2]
Make your own timers, that's what i say ;o)

This should do the trick:

Graphics3D 800,600
SetBuffer BackBuffer()



Global camera = CreateCamera()
PositionEntity camera,0,0,-20

Global light = CreateLight()

Global cube = CreateCube()
PositionEntity cube,-10,0,0

Global timer = MilliSecs()
Global time = 5000

Global move_x = 1
Global move_y = 0
Global move_z = 0


While Not KeyHit(1)

	; IF the value of millisecs() is GREATER than the PREVIOUS value of millisecs() held in TIMER
	; PLUS the value of time, then your 5 seconds has pass
	If MilliSecs() > time + timer Then
		timer = MilliSecs() ; reset the timer to the current value of millisecs()
		MoveEntity cube,move_x,move_y,move_z ; moves the cube, according to the variable
	End If


	UpdateWorld
	RenderWorld
	Flip
Wend
End