-
Movements & Timer
I am making a falling game, where things fall and you have to avoid them. I'm using pictureboxes as the falling objects which are connected to a timer but I'm not really sure how to make it so then once the game stats the objects start falling. I know to go down is PictureBox.Top = PictureBox.Top -5 or whatever number, but how would I write it for a timer. I'm new to VB.Net.
-
Re: Movements & Timer
Hi
I assume you know a little bit about a timer
1 you start the timer
2 the timer counts down
3 when countdown is 0 then the 'Tick' event is fired
---you would put your frame update code in the tick event
4 timer starts again(as long as its set to, by default it will repeat)
tips with the coding:
when i say frame-update code that means EVERYTHING that changes in game should be calculated here in the tick event.
keyboard presses, object movement, colision detection(if any), score updates,
Recommendation:
due to having some sort of problem using a timer in many different situations i recommend creating a loop of you own and putting an if statement to fire after a certain time has passed. using system clock ticks as a time reference, its really simple
tickcount= 'system clock ticks'
while playinggame = true 'game started'
if tickcount + 100 <= systemtickcount then 'tickcount+100 <= systemtickcount which means at least 100ms has passed before the frame is updated
<frame update code here>
tickcount = systemtickcount
end if
wend
dont forget to stop the loop when the game has ended or someone died etc,
playinggame = false
hope this helps
-
Re: Movements & Timer
Heres a quickreference on system tick count
<<LINK>>