181 lines
5.8 KiB
JavaScript
181 lines
5.8 KiB
JavaScript
cc.Class({
|
|
extends: cc.Component,
|
|
properties: {
|
|
moveSpeed: 100,
|
|
gameList: {
|
|
default: null,
|
|
type: cc.Node,
|
|
displayName: "游戏"
|
|
},
|
|
nameBj: {
|
|
default: [],
|
|
type: cc.SpriteFrame,
|
|
displayName: "游戏名字背景"
|
|
},
|
|
isHorizontal: false
|
|
},
|
|
onLoad: function () {
|
|
this.contentNode = this.gameList.getChildByName("contentNode");
|
|
this.contentNode.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
|
|
this.contentNode.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
|
|
this.contentNode.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
|
|
this.contentNode.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
|
|
this.node.getComponent(cc.Widget) && this.node.getComponent(cc.Widget).updateAlignment();
|
|
this.gameList || (this.gameList = this.node);
|
|
this.gameNameBjIndex = 0;
|
|
this.moveSpeed = 80;
|
|
this.isGoUp = true;
|
|
this.isMayMove = true;
|
|
this.showID = 0;
|
|
this.changeTime = 0;
|
|
if (window.swan && window.GameConfig.iconList && window.GameConfig.packageList) {
|
|
if (window.GameConfig.packageList.length <= 0 || window.GameConfig.packageList.length <= 0) {
|
|
this.node.active = false;
|
|
} else {
|
|
this.showIcon();
|
|
}
|
|
} else {
|
|
this.node.active = false;
|
|
}
|
|
},
|
|
start: function () {},
|
|
showIcon: function () {
|
|
for (var e = 0; e < window.GameConfig.iconList.length; e++) {
|
|
var o = this.gameList.getChildByName("contentNode").children[e];
|
|
console.log();
|
|
o || ((o = cc.instantiate(this.gameList.getChildByName("contentNode").children[0])).parent = this.gameList.getChildByName("contentNode"));
|
|
o.showID = e;
|
|
var t = o.getChildByName("icon");
|
|
window.swan && t.getComponent("ShowImgScript").onShowImg_server(window.GameConfig.iconList[e]);
|
|
}
|
|
this.gameList.getChildByName("contentNode").getComponent(cc.Layout).updateLayout();
|
|
this.maxX = 0;
|
|
this.minX = -1 * (this.contentNode.width - this.gameList.width);
|
|
this.maxY = this.contentNode.height - this.gameList.height;
|
|
this.minY = 0;
|
|
},
|
|
touchIconCallBack: function (e) {
|
|
var o = parseInt(e.target.showID);
|
|
if (console.log("showID=", o), window.tt) {
|
|
"ios" === window.tt.getSystemInfoSync().platform && window.tt.showToast({
|
|
title: " iOS不支持此功能"
|
|
});
|
|
window.tt.showMoreGamesModal({
|
|
appLaunchOptions: [{
|
|
appId: "",
|
|
query: "foo=bar&baz=qux",
|
|
extraData: {}
|
|
}],
|
|
success: function (e) {},
|
|
fail: function (e) {}
|
|
});
|
|
} else if (window.qg) {
|
|
window.qg.navigateToMiniGame({
|
|
pkgName: window.GameConfig.packageList[o],
|
|
path: "?page=pageB",
|
|
extraData: {
|
|
from: "脑洞侦探"
|
|
},
|
|
success: function () {},
|
|
fail: function (e) {
|
|
console.log(JSON.stringify(e));
|
|
}
|
|
});
|
|
} else {
|
|
window.swan && window.swan.navigateToMiniProgram({
|
|
appKey: window.GameConfig.packageList[o],
|
|
path: "/path/page/0",
|
|
extraData: {
|
|
from: "脑洞侦探"
|
|
},
|
|
success: function () {},
|
|
fail: function (e) {
|
|
console.log(JSON.stringify(e));
|
|
}
|
|
});
|
|
}
|
|
},
|
|
onJumpToOtherGame: function (e) {
|
|
e || (e = 0);
|
|
window.swan && window.swan.navigateToMiniProgram({
|
|
appKey: window.GameConfig.packageList[e],
|
|
path: "/path/page/0",
|
|
extraData: {
|
|
from: "抢滩夺岛战"
|
|
},
|
|
success: function () {},
|
|
fail: function (e) {
|
|
console.log(JSON.stringify(e));
|
|
}
|
|
});
|
|
},
|
|
onButtonClick: function (e) {
|
|
switch (e.target.name) {
|
|
case "btn_close":
|
|
this.node.removeFromParent();
|
|
}
|
|
},
|
|
onTouchStart: function (e) {
|
|
this.isMayMove = false;
|
|
this.firstTouchPoint = this.contentNode.convertToNodeSpaceAR(e.getLocation());
|
|
},
|
|
onTouchMove: function (e) {
|
|
if (1 != this.isMayMove) {
|
|
var o = e.getDelta().x;
|
|
var t = e.getDelta().y;
|
|
if (1 == this.isHorizontal) {
|
|
this.contentNode.x += o;
|
|
this.contentNode.x <= this.minX && (this.contentNode.x = this.minX);
|
|
this.contentNode.x >= this.maxX && (this.contentNode.x = this.maxX);
|
|
} else {
|
|
this.contentNode.y += t;
|
|
this.contentNode.y <= this.minY && (this.contentNode.y = this.minY);
|
|
this.contentNode.y >= this.maxY && (this.contentNode.y = this.maxY);
|
|
}
|
|
}
|
|
},
|
|
onTouchEnd: function (e) {
|
|
if (!this.isMayMove) {
|
|
this.isMayMove = true;
|
|
var o = this.contentNode.convertToNodeSpaceAR(e.getLocation());
|
|
if (this.firstTouchPoint.sub(o).mag() < 10) {
|
|
var t = this.contentNode.children;
|
|
for (var i = 0; i < t.length; i++) {
|
|
var n = t[i];
|
|
if (n.getBoundingBox().contains(o)) {
|
|
var a = n.showID;
|
|
this.onJumpToOtherGame(a);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
update: function (e) {
|
|
if (this.isMayMove) {
|
|
if (1 == this.isHorizontal) {
|
|
if (1 == this.isGoUp) {
|
|
this.contentNode.x += this.moveSpeed * e;
|
|
if (this.contentNode.x >= this.maxX) {
|
|
this.contentNode.x = this.maxX, this.isGoUp = false;
|
|
}
|
|
} else {
|
|
this.contentNode.x -= this.moveSpeed * e;
|
|
if (this.contentNode.x <= this.minX) {
|
|
this.contentNode.x = this.minX, this.isGoUp = true;
|
|
}
|
|
}
|
|
} else if (1 == this.isGoUp) {
|
|
this.contentNode.y += this.moveSpeed * e;
|
|
if (this.contentNode.y >= this.maxY) {
|
|
this.contentNode.y = this.maxY, this.isGoUp = false;
|
|
}
|
|
} else {
|
|
this.contentNode.y -= this.moveSpeed * e;
|
|
if (this.contentNode.y <= this.minY) {
|
|
this.contentNode.y = this.minY, this.isGoUp = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}); |