forked from mozilla/BrowserQuest
-
Notifications
You must be signed in to change notification settings - Fork 219
/
tile.js
37 lines (31 loc) · 849 Bytes
/
tile.js
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
define(function() {
var Tile = Class.extend({
});
var AnimatedTile = Tile.extend({
init: function(id, length, speed, index) {
this.startId = id;
this.id = id;
this.length = length;
this.speed = speed;
this.index = index;
this.lastTime = 0;
},
tick: function() {
if((this.id - this.startId) < this.length - 1) {
this.id += 1;
} else {
this.id = this.startId;
}
},
animate: function(time) {
if((time - this.lastTime) > this.speed) {
this.tick();
this.lastTime = time;
return true;
} else {
return false;
}
}
});
return AnimatedTile;
});