-
Notifications
You must be signed in to change notification settings - Fork 596
/
AnimationCallback.js
100 lines (84 loc) · 2.56 KB
/
AnimationCallback.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
98
99
100
cc.Class({
extends: cc.Component,
properties: {
playLabel: {
default: null,
type: cc.Label
},
pauseLabel: {
default: null,
type: cc.Label
},
stateLabel: {
default: null,
type: cc.Label
},
animation: {
default: null,
type: cc.Animation
}
},
onEnable: function () {
var animation = this.animation;
animation.on('play', this.onPlay, this);
animation.on('stop', this.onStop, this);
animation.on('lastframe', this.onLastFrame, this);
animation.on('finished', this.onFinished, this);
animation.on('pause', this.onPause, this);
animation.on('resume', this.onResume, this);
},
onDisable: function () {
var animation = this.animation;
animation.off('play', this.onPlay, this);
animation.off('stop', this.onStop, this);
animation.off('lastframe', this.onLastFrame, this);
animation.off('finished', this.onFinished, this);
animation.off('pause', this.onPause, this);
animation.off('resume', this.onResume, this);
},
onPlayButtonClicked: function () {
if (this.playLabel.string === 'play') {
this.playLabel.string = 'stop';
this.animation.play('linear');
}
else {
this.playLabel.string = 'play';
this.animation.stop('linear');
}
},
onPauseButtonClicked: function () {
if (this.pauseLabel.string === 'pause') {
this.pauseLabel.string = 'resume';
this.animation.pause('linear');
}
else {
this.pauseLabel.string = 'pause';
this.animation.resume('linear');
}
},
onPlay: function () {
cc.log('onPlay');
this.stateLabel.string = 'onPlay';
},
onStop: function () {
cc.log('onStop');
this.stateLabel.string = 'onStop';
this.playLabel.string = 'play';
},
onLastFrame: function () {
cc.log('onLastFrame');
this.stateLabel.string = 'onLastFrame';
},
onFinished: function () {
cc.log('onFinished');
this.stateLabel.string = 'onFinished';
},
onPause: function () {
cc.log('onPause');
this.stateLabel.string = 'onPause';
},
onResume: function () {
cc.log('onResume');
this.stateLabel.string = 'onResume';
}
});