-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathparenttest.js
56 lines (50 loc) · 1.11 KB
/
parenttest.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
kaplay();
loadBean();
const centerBean = add([
pos(center()),
anchor("center"),
sprite("bean"),
area(),
rotate(0),
scale(2),
{
update() {
this.angle += 20 * dt();
},
},
]);
const orbitingBean = centerBean.add([
pos(vec2(100, 0)),
anchor("center"),
sprite("bean"),
area(),
rotate(0),
scale(1),
color(),
{
update() {
this.angle = -this.parent.transform.getRotation();
if (this.isHovering()) {
this.color = RED;
}
else {
this.color = WHITE;
}
},
},
]);
onMousePress(() => {
if (orbitingBean.parent === centerBean /* && orbitingBean.isHovering()*/) {
orbitingBean.setParent(getTreeRoot(), { keep: KeepFlags.All });
}
});
onMouseMove((pos, delta) => {
if (orbitingBean.parent !== centerBean) {
orbitingBean.pos = orbitingBean.pos.add(delta);
}
});
onMouseRelease(() => {
if (orbitingBean.parent !== centerBean) {
orbitingBean.setParent(centerBean, { keep: KeepFlags.All });
}
});