-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdice-better-animated.js
88 lines (65 loc) · 1.72 KB
/
dice-better-animated.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
const { Button, ui, ImageView} = require('tabris');
const IMAGE_PATH = 'https://mrmccormack.github.io/imd-learning-tabris/images/';
const DICE_OFFSET = 30;
// https://www.freepik.com/free-vector/illustration-of-a-set-of-red-dices_1164307.htm#term=dice&page=1&position=2
// free for commercial usewith attribution
diceImage1 = new ImageView({
top: 150,
left: 150, width: 50, height: 50,
image: IMAGE_PATH + '1.jpg'
}).appendTo(ui.contentView);
let diceImage2 = new ImageView({
top: 150,
left: 50, width: 50, height: 50,
image: IMAGE_PATH + '6.jpg'
}).appendTo(ui.contentView);
// button with event inside
let btnAnimate = new Button({
left: 50,
top: 'prev() 10',
text: 'Animate',
})
.on('select', () => {
//console.log ('you pressed btnAnimate');
// this works btnAnimate.visible = false;
let rand = 1 + Math.floor(Math.random() * 6);
diceImage1.image = IMAGE_PATH + rand + '.jpg';
let rand1 = 1 + Math.floor(Math.random() * 6);
diceImage2.image = IMAGE_PATH + rand1 + '.jpg';
let messDoubles = "";
if (rand==rand1){
messDoubles = "You rolled doubles: "
}
else{
messDoubles = "You rolled: "
}
totalDice = rand1 + rand;
btnAnimate.text = messDoubles + totalDice;
diceImage2.animate({
//opacity: 0,
transform: {
rotation: 6 * Math.PI,
scaleX: 2,
scaleY: 2
//scaleX: 2
}
}, {
duration: 200,
//easing: 'ease-out',
repeat: 1,
reverse: true,
}).then(() => label.dispose());
diceImage1.animate({
//opacity: 0,
transform: {
rotation: -4 * Math.PI,
scaleX: 2,
scaleY: 2
}
}, {
duration: 300,
//easing: 'ease-out',
repeat: 1,
reverse: true,
}).then(() => label.dispose());
}).appendTo(ui.contentView);