File tree 2 files changed +35
-7
lines changed
website/source/assets/javascripts
2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,10 @@ Engine = Base.extend({
68
68
this . background . className += ' show' ;
69
69
this . canvas . style . opacity = 1 ;
70
70
71
- new Chainable ( )
71
+ // We have to pass the engine into Chainable to
72
+ // enable the timers to properly attach to the
73
+ // run/render loop
74
+ new Chainable ( this )
72
75
. wait ( 1000 )
73
76
. then ( function ( ) {
74
77
this . starGeneratorRate = 200 ;
@@ -202,6 +205,13 @@ Engine = Base.extend({
202
205
this . now = Date . now ( ) / 1000 ;
203
206
this . tick = Math . min ( this . now - this . last , 0.017 ) ;
204
207
208
+ // We must attach the chainable timer to the engine
209
+ // run/render loop or else things can get pretty
210
+ // out of wack
211
+ if ( this . updateChainTimer ) {
212
+ this . updateChainTimer ( this . tick ) ;
213
+ }
214
+
205
215
// Update all particles... may need to be optimized
206
216
for ( p = 0 ; p < this . particles . length ; p ++ ) {
207
217
this . particles [ p ] . update ( this ) ;
Original file line number Diff line number Diff line change 1
1
( function ( ) {
2
2
3
- var Chainable = function ( ) {
3
+ var Chainable = function ( engine ) {
4
+ this . engine = engine ;
4
5
this . _chain = [ ] ;
6
+ this . _updateTimer = this . _updateTimer . bind ( this ) ;
5
7
this . _cycle = this . _cycle . bind ( this ) ;
6
8
} ;
7
9
8
10
Chainable . prototype . _running = false ;
9
11
12
+ Chainable . prototype . _updateTimer = function ( tick ) {
13
+ this . _timer += tick ;
14
+ if ( this . _timer >= this . _timerMax ) {
15
+ this . resetTimer ( ) ;
16
+ this . _cycle ( ) ;
17
+ }
18
+ } ;
19
+
20
+ Chainable . prototype . resetTimer = function ( ) {
21
+ this . engine . updateChainTimer = undefined ;
22
+ this . _timer = 0 ;
23
+ this . _timerMax = 0 ;
24
+ return this ;
25
+ } ;
26
+
10
27
Chainable . prototype . start = function ( ) {
11
28
if ( this . _running || ! this . _chain . length ) {
12
29
return this ;
@@ -19,9 +36,8 @@ Chainable.prototype.reset = function(){
19
36
if ( ! this . _running ) {
20
37
return this ;
21
38
}
22
- clearTimeout ( this . _timer ) ;
23
- this . _timer = null ;
24
- this . _chain . length = 0 ;
39
+ this . resetTimer ( ) ;
40
+ this . _timer = 0 ;
25
41
this . _running = false ;
26
42
return this ;
27
43
} ;
@@ -40,8 +56,10 @@ Chainable.prototype._cycle = function(){
40
56
return this . _cycle ( ) ;
41
57
}
42
58
if ( current . type === 'wait' ) {
43
- clearTimeout ( this . _timer ) ;
44
- this . _timer = setTimeout ( this . _cycle , current . time || 0 ) ;
59
+ this . resetTimer ( ) ;
60
+ // Convert timer to seconds
61
+ this . _timerMax = current . time / 1000 ;
62
+ this . engine . updateChainTimer = this . _updateTimer ;
45
63
current = null ;
46
64
}
47
65
You can’t perform that action at this time.
0 commit comments