-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathhover.js
60 lines (48 loc) · 1.04 KB
/
hover.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
// @ts-check
// Differeces between onHover and onHoverUpdate
kaplay({
// Use logMax to see more messages on debug.log()
logMax: 5,
});
loadSprite("bean", "/sprites/bean.png");
add([
text("onHover()\nonHoverEnd()"),
pos(80, 80),
]);
add([
text("onHoverUpdate()"),
pos(340, 80),
]);
const redBean = add([
sprite("bean"),
color(RED),
pos(130, 180),
anchor("center"),
area(),
]);
const blueBean = add([
sprite("bean"),
color(BLUE),
pos(380, 180),
anchor("center"),
area(),
]);
// Only runs once when bean is hovered, and when bean is unhovered
redBean.onHover(() => {
debug.log("red bean hovered");
redBean.color = GREEN;
});
redBean.onHoverEnd(() => {
debug.log("red bean unhovered");
redBean.color = RED;
});
// Runs every frame when blue bean is hovered
blueBean.onHoverUpdate(() => {
const t = time() * 10;
blueBean.color = rgb(
wave(0, 255, t),
wave(0, 255, t + 2),
wave(0, 255, t + 4),
);
debug.log("blue bean on hover");
});