-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
113 lines (85 loc) · 3.54 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>game-timer</title>
<link rel="stylesheet" href="/css/style.css" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-10931011-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<a href="https://github.com/jensarps/game-timer"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
<div id="container">
<h1><a href="https://github.com/jensarps/game-timer">game-timer</a></h1>
<div class="description">
A simple timer to use in combination with a render loop. Provides timeout and interval methods as found on window.
</div>
<h2>About</h2>
<p>
For games, the built-in timers are not suitable, mainly because of the
following two reasons:
</p>
<ol>
<li>If you pause the game, the built-in timer won't pause as well.</li>
<li>You will want to fire callbacks within your render loop, not somewhere else.</li>
</ol>
<p>
This timer does not maintain it's own clock, so you need to call `update()`
in your render loop.
</p>
<h2>Notes</h2>
<ol>
<li>
If you use it w/ Three.js, keep in mind that the delta obtained by Three.js' clock.getDelta() is in seconds, not milliseconds!
</li>
<li>This timer, by default, does not modify the execution context of
the callbacks. You can, however pass a context to the set* methods. If
you don't provide a context object, or don't bind the callbacks
yourself, the execution context will be the timer instance!
</li>
</ol>
<h2>Usage</h2>
<p>
Include the timer.js file via script tag or pull it in using an AMD loader
like require.js.
</p>
<pre><code>
var timer = new Timer();
// setting an interval works like window.setInterval:
var intervalId = timer.setInterval(someFunc, 100);
// to set the execution context, pass a context object:
var intervalId = timer.setInterval(someFunc, 100, someObj);
// or bind your function:
var intervalId = timer.setInterval(someFunc.bind(somObj), 100);
// then, in your render loop:
function render(){
//...
timer.update(delta); // delta needs to be in ms!
}
// clearing also works as expected:
timer.clearInterval(intervalId);
</code></pre>
<h2>Demo</h2>
<p>You can see how it works <a href="demo/">here</a>.</p>
<h2>Tests</h2>
<p>You can run the tests <a href="tests/SpecRunner.html">here</a>.</p>
<h2>License</h2>
<p><a href="https://github.com/jensarps/game-timer/blob/master/LICENSE">MIT style (X11)</a></p>
<h2>Author</h2>
<p><a href="https://github.com/jensarps">Jens Arps</a></p>
<h2>Contact</h2>
<p>Ping me on Twitter: <a href="https://twitter.com/#!/jensarps">@jensarps</a></p>
<div class="footer">
get the source code on GitHub : <a href="https://github.com/jensarps/game-timer">jensarps/game-timer</a>
</div>
</div>
</body>
</html>