-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCamera.js
executable file
·52 lines (47 loc) · 909 Bytes
/
Camera.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Camera class keeps track of the current
* drawing position
*/
define(['./jo','./Point'],
function(jo,
Point){
jo.Camera = Point.extend({
init: function(){
this._super(0,0);
},
toScreen: function(p){
if(typeof p =='undefined'){
return this.neg();
}
return (p.minus(this)).floor();
},
toWorld: function(p){
if(typeof p =='undefined'){
return this;
}
return (p.plus(this)).floor();
},
toMap: function(p, tilesize){
if(typeof p === 'undefined'){
return null;
}
if(! tilesize){
tilesize = 64;
}
var tw = th = tilesize;
p = this.toWorld(p);
p.x/=tw;
p.y/=th;
return p.floor();
},
parrallax: function(val, width, height){
var para = this.mul(val);
para.x = para.x % width;
para.y = para.y % height;
return para.negate();
},
snap: function(amount){
}
});
return jo.Camera;
});