-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJAXAniAuto.js
More file actions
198 lines (185 loc) · 4.74 KB
/
JAXAniAuto.js
File metadata and controls
198 lines (185 loc) · 4.74 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import {JAXEnv} from './JAXEnv.js';
import {JAXAni} from "./JAXAni.js";
import {JAXAniFade} from "./JAXAniFade.js";
import {JAXAniPose} from "./JAXAniPose.js";
const STATE_NONE=0;
const STATE_READY=1;
const STATE_ANI=2;
const STATE_PAUSED=3;
const STATE_END=4;
const STATE_CANCELED=5;
var JAXAniAuto,__Proto;
JAXAniAuto=function(env,def,hud){
if(!env)
return;
this.orgDisplay=1;
this.orgX=0;
this.orgY=0;
this.orgW=0;
this.orgH=0;
this.orgAlpha=1;
this.orgScale=1;
this.orgRotate=0;
this.aniObj=null;
JAXAni.call(this,env,def,hud);
};
__Proto=JAXAniAuto.prototype=new JAXAni();
//***************************************************************************
//通用接口:
//***************************************************************************
{
//-----------------------------------------------------------------------
//初始化:
__Proto.initByDef = function (def) {
if (this.def) {
this.jaxEnv.logError("Ani already inited.");
return;
}
this.def = def;
this.OnFinish = def.OnFinish;
this.OnCancel = def.OnCancel;
if (this.hud) {
this.state = STATE_READY;
}
};
//-----------------------------------------------------------------------
//与Hud绑定:
__Proto.bind2Hud = function (hud) {
this.hud = hud;
if (this.def) {
this.state = STATE_READY;
}
this.orgDisplay=hud.display;
this.orgX=hud.x;
this.orgY=hud.y;
this.orgW=hud.w;
this.orgH=hud.h;
this.orgAlpha=hud.alpha;
this.orgScale=hud.scale;
this.orgRotate=hud.rotate;
};
//-----------------------------------------------------------------------
//开始动画
__Proto.start = function () {
let div,def,self,hud,aniObj,aniDef;
if (this.state !== STATE_READY) {
this.jaxEnv.logError("Ani not ready!");
return;
}
self=this;
hud=this.hud;
def=this.def;
aniObj=null;
aniDef={};
if(hud.display && !this.orgDisplay){
//使用FadeIn
aniDef.type="in";
aniDef.dx=def.dx||0;
aniDef.dy=def.dy||0;
aniDef.alpha=def.alpha||0;
aniDef.scale=def.scale||this.orgScale;
aniDef.time=def.time||200;
aniObj=new JAXAniFade(this.jaxEnv,aniDef,hud);
}else if(!hud.display && this.orgDisplay){
//使用FadeOut
aniDef.type="out";
aniDef.dx=def.dx||0;
aniDef.dy=def.dy||0;
aniDef.alpha=def.alpha||0;
aniDef.scale=def.scale||this.orgScale;
aniDef.time=def.time||200;
aniObj=new JAXAniFade(this.jaxEnv,aniDef,hud);
}else if(hud.display){
//使用Pose
aniDef.type="pose";
aniDef.x=hud.x;
aniDef.y=hud.y;
aniDef.w=hud.w;
aniDef.h=hud.h;
aniDef.alpha=hud.alpha;
aniDef.scale=hud.scale;
aniDef.time=def.time||200;
aniObj=new JAXAniPose(this.jaxEnv,aniDef,hud);
//TODO: 是否重置Hud状态:
hud.x=this.orgX;
hud.y=this.orgY;
hud.w=this.orgW;
hud.h=this.orgH;
hud.alpha=this.orgAlpha;
hud.scale=this.orgScale;
hud.rotate=this.orgRotate;
}else{
this.jaxEnv.callAfter(()=>{
self.OnFinish&&self.OnFinish();
self.aniObj=null;
});
return;
}
this.aniObj=aniObj;
if(aniObj){
aniObj.start(def.time);
this.aniObj.OnFinish=function(){
self.OnFinish&&self.OnFinish();
self.aniObj=null;
};
this.aniObj.OnCancel=function(){
self.OnCancel&&self.OnCancel();
self.aniObj=null;
};
}
this.state=STATE_ANI;
};
//-----------------------------------------------------------------------
//暂停动画:
__Proto.pause = function () {
if(this.state!==STATE_ANI){
this.jaxEnv.logError("Ani not playing!");
return;
}
this.aniObj.pause();
this.state=STATE_PAUSED;
};
//-----------------------------------------------------------------------
//恢复动画:
__Proto.resume = function () {
if(this.state!==STATE_PAUSED){
this.jaxEnv.logError("Ani not paused!");
return;
}
this.aniObj.resume();
this.state=STATE_ANI;
};
//-----------------------------------------------------------------------
//结束动画:
__Proto.finish = function () {
if(this.state!==STATE_PAUSED && this.state!==STATE_ANI){
this.jaxEnv.logError("Can't stop ani!");
return;
}
this.aniObj.finish();
this.aniObj=null;
this.state=STATE_END;
};
//-----------------------------------------------------------------------
//取消动画:
__Proto.cancel = function () {
if(this.state!==STATE_PAUSED && this.state!==STATE_ANI){
this.jaxEnv.logError("Can't stop ani!");
return;
}
this.aniObj.cancel();
this.aniObj=null;
this.state=STATE_CANCELED;
};
}
//***************************************************************************
//注册类型:
//***************************************************************************
{
//-----------------------------------------------------------------------
//注册动画类型:
JAXAni.regHudByType("auto",function(env,def,hud){
return new JAXAniAuto(env,def,hud)
});
}
export {JAXAniAuto};