ExploreNew.js
15.5 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
var Common = require('Common');
var Network = require('Network');
var TVFocus = require('TVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var TVScrollParameter = require('TVScrollParameter');
var ListView = require('ListView');
var ListCell = require('ListCell');
var xmlToJSON = require('xmlToJSON');
var GlobalValue = require('GlobalValue');
cc.Class({
extends: TVCanvas,
properties: {
_speed: 0,
PFB_TYPE: {
default: null,
type: cc.Prefab,
},
PFB_POP: {
default: null,
type: cc.Prefab,
},
},
start: function () {
// this.bg_long.getComponent(cc.Animation).play(); //动画滚动背景,因为动画背景尺寸较大,再真机中黑屏
// this.schedule(()=>{
// this.bg_long.getComponent(cc.Animation).pause(); //暂停播放动画
// this.hero.getComponent(dragonBones.ArmatureDisplay)._armature.animation.stop();
// },5);
this.scheduleOnce(() => { //指定0让回调函数在下一帧立即执行(推荐位初始化图片后,需等待下一帧操作)
this.bg_long.getComponent(cc.Animation).pause();
}, 0);
},
onLoad: function () {
this._super();
let oSceneParameter = this._cApplication.getTopSceneParameter();
if (oSceneParameter) {
this._islandOrder = oSceneParameter.order-1; //当前位于哪个岛屿,岛屿从1开始排序,故需要-1
}
//------------------滚动背景-------------------
this._speed=0;
this.bg_1 = this.node.getChildByName("bg_1");
this.bg_2 = this.node.getChildByName("bg_2");
this.cur_bg = this.bg_1;
//---------------------------------------------
this._aFocusTargets[1] = []; //弹窗焦点
this._iSceneStatus = 0; //焦点层级
this._remindString = this.node.getChildByName("Remind").getComponent(cc.Label);
this._progressString = cc.find("Progress/progress", this.node).getComponent(cc.Label);
this._progressBg = cc.find("Progress/scrollViewBg", this.node);
this._progressBar = cc.find("Progress/scrollViewBg/scrollViewBar", this.node);
cc.log("-------------------->"+this._islandOrder);
this.totalTask = GlobalValue.ISLAND_CONFIG[this._islandOrder].EXPLORE_TOTAL_TASK; //任务进度,根据配置表,
this._progressString.string = 20 * this.totalTask + "%"; //处理上方任务进度条
this._progressBar.width = 20 * this.totalTask / 100 * 800;
cc.log("进来的任务进度表:" + this.totalTask);
this.bg_long = this.node.getChildByName("Bg_long");
// this.bg_long.getComponent(cc.Animation).play(); //播放动画
// this.bg_long.getComponent(cc.Animation).stop(); //暂停播放动画
this.hero = this.node.getChildByName("Hero");
// this.hero.getComponent(dragonBones.ArmatureDisplay).playAnimation();
// this.hero.getComponent(dragonBones.ArmatureDisplay)._armature.animation.stop();
var self = this;
//动态加载背景图,需指定类型(需要拼接图片),指定尺寸(目前使用的是7280*720)
cc.loader.loadRes("game/explore_plus", cc.Texture2D, function (err, texture) {
self.bg_long.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
});
//显示向右的动作指引
let actionUp = cc.moveTo(0.3, cc.v2(480, 0));
let actionDown = cc.moveTo(0.3, cc.v2(500, 0));
this.node.getChildByName("Next").runAction(cc.repeatForever(cc.sequence(actionUp, actionDown)));
//分类框框
this._nodeDialogListWrapper = cc.find("PopWindow/DialogListArea/DialogListWrapper", this.node);
this._nodeDialogList = cc.find("DialogList", this._nodeDialogListWrapper);
// this._nodeDialogList.addComponent(TVScrollParameter);
cc.loader.loadRes("config/explore_config_json", function (err, str) {
// var x2js = new xmlToJSON();
// self._exploreConfig = x2js.xml_str2json(str); //解析xml,打包APK崩溃,无法使用!
self._exploreConfig = str.json;
cc.log("解析后xml------------>" + JSON.stringify(str));
});
this.initFocus();
},
initFocus: function () {
var fiNext = this.node.getChildByName("Next").addComponent(FocusInfo);//
this._aFocusTargets[0]['to_next'] = this.node.getChildByName("Next");
fiNext.init(
null, true
);
var fiClose = this.node.getChildByName("BackAScene").addComponent(FocusInfo);//
this._aFocusTargets[0]['to_back_scene'] = this.node.getChildByName("BackAScene");
fiClose.init(
'', true
);
var fiDiloaClose = cc.find("PopWindow/Close", this.node).addComponent(FocusInfo);//
this._aFocusTargets[1]['to_close_popwindow'] = cc.find("PopWindow/Close", this.node);
fiDiloaClose.init(
'{"click": [{"action": "Close"}]}', true
);
var nodeFocus = new cc.Node('nodeFocus');
this.node.addChild(nodeFocus, 10);
this._cFocus = this.node.getChildByName('nodeFocus').addComponent(TVFocus);
this._cFocus.init('focusContainer', this,
fiNext.getComponent(FocusInfo),
Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, 6, 4, 1.0);
// this._cFocus.hide(); //所有焦点都是隐藏的
},
keyDownDirection: function (Direct) {
var fiFocusTarget = null;
var fiCurrentFocus = this._fiCurrentFocus;
var oScrollParameter = null;
fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Direct);
fiFocusTarget = this.checkFocusTarget(fiFocusTarget);
if (!fiFocusTarget) { return; }
// this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
// this.scheduleOnce(() => { //指定0让回调函数在下一帧立即执行(推荐位初始化图片后,需等待下一帧操作)
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
// }, 0.5);
},
checkFocusTarget: function (fiFocusTarget) {
return fiFocusTarget;
},
onKeyDown: function (event) {
switch (event.keyCode) {
case cc.macro.KEY.up:
case Common.ANDROID_KEY.up:
this.keyDownDirection(Common.MOVE_DIRECTION_UP);
break;
case cc.macro.KEY.right:
case Common.ANDROID_KEY.right:
this.keyDownDirection(Common.MOVE_DIRECTION_RIGHT);
break;
case cc.macro.KEY.down:
case Common.ANDROID_KEY.down:
this.keyDownDirection(Common.MOVE_DIRECTION_DOWN);
break;
case cc.macro.KEY.left:
case Common.ANDROID_KEY.left:
this.keyDownDirection(Common.MOVE_DIRECTION_LEFT);
break;
case cc.macro.KEY.enter:
case cc.macro.KEY.space:
case Common.ANDROID_KEY.enter:
if (0 == this._fiCurrentFocus.node.getName().indexOf('Next')) {
this.nextTask();
break;
} else if (0 == this._fiCurrentFocus.node.getName().indexOf('BackAScene')) {
this.backAScene();
}
this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
break;
case cc.macro.KEY.backspace:
case Common.ANDROID_KEY.back:
this.backAScene();
break;
}
},
/**
* 点击触发下一个事件
*/
nextTask: function () {
// cc.log("播放事件");
if (this.totalTask == 5) {
this._remindString.string = "恭喜,您已经通关!";
this._remindString.node.active = true;
this.scheduleOnce(() => {
this._remindString.node.active = false;
}, 3);
return;
}
// this.bg_long.getComponent(cc.Animation).resume(); //播放动画
this._speed=1;
this.hero.getComponent(dragonBones.ArmatureDisplay).playAnimation("Animation1");
this.scheduleOnce(() => {
// this.bg_long.getComponent(cc.Animation).pause(); //暂停播放动画
this._speed=0;
// this.hero.getComponent(dragonBones.ArmatureDisplay)._armature.animation.stop(); //APK不支持
this.hero.getComponent(dragonBones.ArmatureDisplay).playAnimation("Animation1").stop();
let randomNum = this.random(1, 7);
cc.log("随机数-------->" + randomNum);
var exploreObj = this._exploreConfig.root.explore[randomNum - 1];
// cc.log("对象----->" + JSON.stringify(exploreObj));
var type = exploreObj["_type"];
if (type == 1) { //选择事件,需要用户进行对话框选择,进入相应的功能
this.totalTask += 1;
this.node.getChildByName("Animal").active = true;
this._nodeDialogList.removeAllChildren(); //先清理
for (let i = 0; i < 2; i++) {
let nodeDialogCell = cc.instantiate(this.PFB_TYPE);
nodeDialogCell.y = -nodeDialogCell.height / 2 - i * (nodeDialogCell.height + 20);
this._nodeDialogList.addChild(nodeDialogCell, 10, "DialogCell_" + i);
//准备焦点坐标
let fiDialogBlock = nodeDialogCell.addComponent(FocusInfo);
fiDialogBlock.init('{"click": [{"action": "ChangeScene","parameters": {"sceneName":"sceneProgram"}}]}',
true, null, null, 1.0);
this._aFocusTargets[1]['dialog_list_cell_' + i] = nodeDialogCell;
if (i == 0) {
//让小动物显示1秒再弹窗
this.scheduleOnce(() => {
this._iSceneStatus = 1;
var fiFocusTarget = this._nodeDialogList.getChildByName("DialogCell_0").getComponent(FocusInfo);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_LEFT, null, null);
this.node.getChildByName("PopWindow").active = true;
this.node.getChildByName("PopWindow").zIndex = 10;
this.node.getChildByName("Next").zIndex = 0;
}, 1);
}
}
} else if (type == 2) { //奖励事件,触发后直接获得奖励
this.totalTask += 1;
this._remindString.string = "恭喜您发现了宝箱!";
this._remindString.node.active = true;
this._remindString.node.getChildByName("Box").active = true;
this.scheduleOnce(() => {
this._remindString.node.getChildByName("Box").active = false;
this._remindString.node.active = false;
}, 2);
let popItem = cc.instantiate(this.PFB_POP);
this.node.addChild(popItem, 100);
this.node.anchorX = 0; //解决飘窗显示位置不在屏幕中央的问题
this.node.anchorY = 0;
function fadeOutBack() {
popItem.destroy(); //用完就销毁
cc.log("处理飘窗彻底消失后的逻辑。。。。。。");
};
let fadeOut = cc.fadeOut(1.0);
let moveBy = cc.moveBy(1, cc.v2(0, 200));
popItem.runAction(moveBy);
popItem.runAction(cc.sequence(fadeOut, cc.callFunc(fadeOutBack)));
} else if (type == 3) { //倒退事件,触发后地图探索进度减少
this.totalTask += 1;
this._remindString.string = "找到了捷径,进度增加20%";
this._remindString.node.active = true;
this.scheduleOnce(() => {
this._remindString.node.active = false;
}, 2);
} else if (type == 4) { //前进事件,触发后地图探索进度增加
if (this.totalTask > 0) this.totalTask -= 1;
this._remindString.string = "迷路了,进度减少20%";
this._remindString.node.active = true;
this.scheduleOnce(() => {
this._remindString.node.active = false;
}, 2);
}
cc.log("----------------" + this.totalTask);
//进度
if (this.totalTask > 5) {
this._remindString.string = "恭喜,您已经通关!";
this._remindString.node.active = true;
this.scheduleOnce(() => {
this._remindString.node.active = false;
}, 2);
}
else if (this.totalTask >= 0) {
this._progressString.string = 20 * this.totalTask + "%";
this._progressBar.width = 20 * this.totalTask / 100 * 800; //800是进度条长度
// cc.log("进度-----》" + this._progressBar.width);
GlobalValue.ISLAND_CONFIG[this._islandOrder].PROGRESS_BAR_VALUE=20 * this.totalTask / 100; //20是:100/该岛屿一共的任务数量,这样暂且使用5个任务量
GlobalValue.ISLAND_CONFIG[this._islandOrder].PROGRESS_LABEL_VALUE=this._progressString.string;
GlobalValue.ISLAND_CONFIG[this._islandOrder].EXPLORE_TOTAL_TASK = this.totalTask;
}
}, 5);
},
/**
产生随机整数,包含下限值,包括上限值
@param {Number} lower 下限
@param {Number} upper 上限
@return {Number} 返回在下限到上限之间的一个随机整数
*/
random: function (lower, upper) {
return Math.floor(Math.random() * (upper - lower + 1)) + lower;
},
doCurrentFocusTVLinkAction: function (strAction) {
let strTVLink = this._fiCurrentFocus.getTVLink();
var joTVLink = null;
try {
joTVLink = JSON.parse(strTVLink);
let jaOperationList = joTVLink.click;
for (let i = 0; i < jaOperationList.length; i++) {
switch (jaOperationList[i].action) {
case 'Close':
this.node.getChildByName("Animal").active = false;
this.node.getChildByName("PopWindow").active = false;
this._iSceneStatus = 0;
var fiFocusTarget = this.node.getChildByName("Next").getComponent(FocusInfo);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_RIGHT, null, null);
break;
default:
this.doTVLinkAction(jaOperationList[i]);
break;
}
}
} catch (error) {
cc.log("runTVLinkAction Exception..." + error);
}
},
update: function (dt) {
this.bg_1.x -= this._speed;
this.bg_2.x -= this._speed;
if (this.cur_bg.x <= -1984) {
if (this.cur_bg == this.bg_2) {
this.bg_2.x = this.bg_1.x + 1984;
this.cur_bg = this.bg_1;
} else {
this.bg_1.x = this.bg_2.x + 1970;
this.cur_bg = this.bg_2;
}
}
},
});