Explore.js
5.3 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
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');
cc.Class({
extends: TVCanvas,
properties: {
_speed: 1,
_hero_start_x: 0,
_hero_end_x: 3648,
_hero_y: 0,
},
onLoad: function () {
this._super();
this._hero_start_x = 400;
this.bg_1 = this.node.getChildByName("bg_1");
this.bg_2 = this.node.getChildByName("bg_2");
this.cur_bg = this.bg_1;
this.testmap = this.node.getChildByName("testmap");
this.animLayer = this.testmap.getComponent(cc.TiledMap).getLayer("Animal");
this.hero = this.node.getChildByName("hero");
this._hero_y = this.hero.y;
this.startRun=true;
},
keyDownDirection: function (Direct) {
var fiFocusTarget = null;
var fiCurrentFocus = this._fiCurrentFocus;
var oScrollParameter = null;
fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, 0, 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:
// this._hero_start_x += 100; //造成误差
this._speed = 1;
this.startRun=true;
// this.hero.getComponent(dragonBones.ArmatureDisplay).playAnimation("Animation1");
// this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
break;
case cc.macro.KEY.backspace:
case Common.ANDROID_KEY.back:
this.backAScene();
break;
}
},
update: function (dt) {
this.bg_1.x -= this._speed;
this.bg_2.x -= this._speed;
this.testmap.x -= this._speed;
this._hero_start_x += this._speed;
if (this.cur_bg.x <= -1820) {
if (this.cur_bg == this.bg_2) {
this.bg_2.x = this.bg_1.x + 1820;
this.cur_bg = this.bg_1;
} else {
this.bg_1.x = this.bg_2.x + 1815;
this.cur_bg = this.bg_2;
}
}
// cc.log("背景图位置:"+this.cur_bg.x);
// cc.log("hero位置--------》" + this._hero_start_x);
var pos = this._getTilePos(cc.v2(this._hero_start_x, 4));
// cc.log("pos位置------------------》"+pos);
// cc.log("位置----------》"+pos);
// if (this._hero_start_x < this._hero_end_x) { //不能超过瓦片地图最长长度
// //判断gid是否为0,该地图位置就会出现障碍物
// var gid = this.animLayer.getTileGIDAt(pos);
// // cc.log("gid========" + gid);
// if (gid != 0 && this.startRun) {
// this.startRun=false;
// this._speed = 0;
// this.hero.getComponent(dragonBones.ArmatureDisplay).playAnimation("");
// }
// }
},
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) {
default:
this.doTVLinkAction(jaOperationList[i]);
break;
}
}
} catch (error) {
cc.log("runTVLinkAction Exception..." + error);
}
},
_getTilePos: function (posInPixel) {
var mapSize = this.testmap.getContentSize();
var tileSize = this.testmap.getComponent(cc.TiledMap).getTileSize();
var x = Math.floor(posInPixel.x / tileSize.width);
var y = Math.floor((mapSize.height - posInPixel.y) / tileSize.height);
return cc.v2(x, y);
},
});