-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphina.childreninteractive.js
97 lines (78 loc) · 2.49 KB
/
phina.childreninteractive.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
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
phina.app.Object2D.prototype.$method('init', function(options) {
this.superInit();
options = ({}).$safe(options, phina.app.Object2D.defaults);
this.position = phina.geom.Vector2(options.x, options.y);
this.scale = phina.geom.Vector2(options.scaleX, options.scaleY);
this.rotation = options.rotation;
this.origin = phina.geom.Vector2(options.originX, options.originY);
this._matrix = phina.geom.Matrix33().identity();
this._worldMatrix = phina.geom.Matrix33().identity();
this.interactive = options.interactive;
this.childrenInteractive = options.childrenInteractive;
this._overFlags = {};
this._touchFlags = {};
this.width = options.width;
this.height = options.height;
this.radius = options.radius;
this.boundingType = options.boundingType;
});
phina.app.Object2D.defaults.interactive = false;
phina.app.Object2D.defaults.childrenInteractive = true;
phina.app.Interactive.prototype.$method('_checkElement', function(element) {
var app = this.app;
// 更新するかを判定
if (element.awake === false) return ;
// 子供を更新
var len = element.children.length;
if (len > 0 && element.childrenInteractive) {
var tempChildren = element.children.slice();
for (var i=0; i<len; ++i) {
this._checkElement(tempChildren[i]);
}
}
// タッチ判定
if (element.interactive) this._checkPoint(element);
});
phina.app.Interactive.prototype.$method('__checkPoint', function(obj, p) {
var prevOverFlag = obj._overFlags[p.id];
var overFlag = obj.hitTest(p.x, p.y);
obj._overFlags[p.id] = overFlag;
var e = {
pointer: p,
interactive: this,
over: overFlag,
};
if (!prevOverFlag && overFlag) {
obj.flare('pointover', e);
if (obj.boundingType && obj.boundingType !== 'none') {
this._holds.push(obj);
}
}
if (prevOverFlag && !overFlag) {
obj.flare('pointout', e);
this._holds.erase(obj);
}
if (overFlag) {
if (p.getPointingStart()) {
obj._touchFlags[p.id] = true;
obj.flare('pointstart', e);
// クリックフラグを立てる
obj._clicked = true;
}
}
if (obj._touchFlags[p.id]) {
obj.flare('pointstay', e);
if (p._moveFlag) {
obj.flare('pointmove', e);
}
}
if (obj._touchFlags[p.id]===true && p.getPointingEnd()) {
obj._touchFlags[p.id] = false;
obj.flare('pointend', e);
if (phina.isMobile() && obj._overFlags[p.id]) {
obj._overFlags[p.id] = false;
obj.flare('pointout', e);
this._holds.erase(obj);
}
}
});