Quote:
Originally Posted by kalinowski5
I'm making game via Internet browser. I made php script wich return a few times (for example 75sec, 40sec and 123sec), so I need 3 span elements with diffrent times.
|
Since you are making a game, I'm going to suggest having a single timer element, as having lots of timeout/interval's running could get to be a pain to debug and could make some browsers really suffer.
I've attached a file with a demo (just change the extension from txt to html).
Note: for just simple count-downs the code is probably overkill
It has a single timer/interval object that starts/stops as listeners are added. The listeners are called at each interval 'tick'.
I created a SecondTimeListener object that will call a specified onChange function only when at least a second has passed.
Anyway, by using only one timer you can maintain performance of your javascript application while using it to handle animation of multiple sprites, timers and whatever other fun things you can come up with.
The window.onload stuff at the bottom kicks everything off. I've got the timer on a 50 millisecond interval (remember, the display only updates every second), you can change it if needed. See the interval property of the Timer object.
|