-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVtron.TouchableObject.js
More file actions
77 lines (52 loc) · 1.76 KB
/
Vtron.TouchableObject.js
File metadata and controls
77 lines (52 loc) · 1.76 KB
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
if(!Vtron){ var Vtron = {}; }
(function (Vtron) {
//Generic Class to Extend and record touches on objects.
Vtron.TouchableObject = new Class({
Extends: Vtron.AnimatedObject,
initialize:function(el) {
var self = this;
this.initTouch = {x:0, y:0};
this.prevTouch = Object.clone(this.initTouch);
this.curTouch = Object.clone(this.initTouch);
this.bTouching = false;
this.bTapPossible = false;
this.parent(el);
el.addEvent('touchstart',function(e){self.start(e)});
el.addEvent('touchmove',function(e){self.move(e)});
el.addEvent('touchend',function(e){self.end(e)});
},
//-------------------------------------------------
setCurTouch: function(x,y) {
this.prevTouch = Object.clone(this.curTouch);
this.curTouch.x = x;
this.curTouch.y = y;
},
//-------------------------------------------------
setPrevTouch: function(x,y) {
this.prevTouch.x = x;
this.prevTouch.y = y;
},
//-------------------------------------------------
start: function(e) {
this.bTouching = true;
this.bTapPossible = true;
if(e.touches.length == 1) {
this.setCurTouch(e.touches[0].screenX,e.touches[0].screenY);
this.initTouch = Object.clone(this.curTouch);
}
},
//-------------------------------------------------
move: function(e) {
if(e.changedTouches.length == 1) {
this.setCurTouch(e.changedTouches[0].screenX,e.changedTouches[0].screenY);
if(Math.abs(this.curTouch.x - this.initTouch.x) > 5 || Math.abs(this.curTouch.y - this.initTouch.y) > 5) {
this.bTapPossible = false;
}
}
},
//-------------------------------------------------
end: function(e) {
if(e.touches.length == 0) this.bTouching = false;
},
});
})(Vtron);