Commit c3ec72f8 authored by 李维's avatar 李维

test

parent ac11f82d
...@@ -83,7 +83,8 @@ cc.Class({ ...@@ -83,7 +83,8 @@ cc.Class({
getData((data) => { getData((data) => {
console.log('data:', data); console.log('data:', data);
this.data = data || this.getDefaultData(); this.data = data || this.getDefaultData();
this.data = JSON.parse(JSON.stringify(this.data)) this.data = JSON.parse(JSON.stringify(this.data));
this.preloadItem()
// this.preloadItem(_=>{ // this.preloadItem(_=>{
// this.gameLogic = new GameLogic(this.data, { // this.gameLogic = new GameLogic(this.data, {
// designSize: this._designSize, // designSize: this._designSize,
...@@ -169,7 +170,7 @@ cc.Class({ ...@@ -169,7 +170,7 @@ cc.Class({
loadEnd() { loadEnd() {
this.initData(); this.initData();
this.initAudio(); this.initAudio();
this.initView(); // this.initView();
// this.initListener(); // this.initListener();
}, },
...@@ -192,145 +193,145 @@ cc.Class({ ...@@ -192,145 +193,145 @@ cc.Class({
}, },
initView() { // initView() {
// this.initBg(); // // this.initBg();
// this.initPic(); // // this.initPic();
// this.initBtn(); // // this.initBtn();
// this.initIcon(); // // this.initIcon();
}, // },
initBg() { // initBg() {
const bgNode = cc.find('Canvas/bg'); // const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax; // bgNode.scale = this._mapScaleMax;
}, // },
pic1: null, // pic1: null,
pic2: null, // pic2: null,
initPic() { // initPic() {
const canvas = cc.find('Canvas'); // const canvas = cc.find('Canvas');
const maxW = canvas.width * 0.7; // const maxW = canvas.width * 0.7;
this.getSprNodeByUrl(this.data.pic_url, (sprNode) => { // this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
const picNode1 = sprNode; // const picNode1 = sprNode;
picNode1.scale = maxW / picNode1.width; // picNode1.scale = maxW / picNode1.width;
picNode1.baseX = picNode1.x; // picNode1.baseX = picNode1.x;
canvas.addChild(picNode1); // canvas.addChild(picNode1);
this.pic1 = picNode1; // this.pic1 = picNode1;
const labelNode = new cc.Node(); // const labelNode = new cc.Node();
labelNode.color = cc.Color.YELLOW; // labelNode.color = cc.Color.YELLOW;
const label = labelNode.addComponent(cc.Label); // const label = labelNode.addComponent(cc.Label);
label.string = this.data.text; // label.string = this.data.text;
label.fontSize = 60; // label.fontSize = 60;
label.lineHeight = 60; // label.lineHeight = 60;
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font; // label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
picNode1.addChild(labelNode); // picNode1.addChild(labelNode);
}); // });
this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => { // this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
const picNode2 = sprNode; // const picNode2 = sprNode;
picNode2.scale = maxW / picNode2.width; // picNode2.scale = maxW / picNode2.width;
canvas.addChild(picNode2); // canvas.addChild(picNode2);
picNode2.x = canvas.width; // picNode2.x = canvas.width;
picNode2.baseX = picNode2.x; // picNode2.baseX = picNode2.x;
this.pic2 = picNode2; // this.pic2 = picNode2;
const labelNode = new cc.Node(); // const labelNode = new cc.Node();
const label = labelNode.addComponent(cc.RichText); // const label = labelNode.addComponent(cc.RichText);
const size = 60 // const size = 60
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font; // label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>` // label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
label.lineHeight = size; // label.lineHeight = size;
picNode2.addChild(labelNode); // picNode2.addChild(labelNode);
}); // });
}, // },
initIcon() { // initIcon() {
const iconNode = this.getSprNode('icon'); // const iconNode = this.getSprNode('icon');
iconNode.zIndex = 5; // iconNode.zIndex = 5;
iconNode.anchorX = 1; // iconNode.anchorX = 1;
iconNode.anchorY = 1; // iconNode.anchorY = 1;
iconNode.parent = cc.find('Canvas'); // iconNode.parent = cc.find('Canvas');
iconNode.x = iconNode.parent.width / 2 - 10; // iconNode.x = iconNode.parent.width / 2 - 10;
iconNode.y = iconNode.parent.height / 2 - 10; // iconNode.y = iconNode.parent.height / 2 - 10;
iconNode.on(cc.Node.EventType.TOUCH_START, () => { // iconNode.on(cc.Node.EventType.TOUCH_START, () => {
this.playAudioByUrl(this.data.audio_url); // this.playAudioByUrl(this.data.audio_url);
}) // })
}, // },
curPage: null, // curPage: null,
initBtn() { // initBtn() {
this.curPage = 0; // this.curPage = 0;
const bottomPart = cc.find('Canvas/bottomPart'); // const bottomPart = cc.find('Canvas/bottomPart');
bottomPart.zIndex = 5; // 提高层级 // bottomPart.zIndex = 5; // 提高层级
bottomPart.x = bottomPart.parent.width / 2; // bottomPart.x = bottomPart.parent.width / 2;
bottomPart.y = -bottomPart.parent.height / 2; // bottomPart.y = -bottomPart.parent.height / 2;
const leftBtnNode = bottomPart.getChildByName('btn_left'); // const leftBtnNode = bottomPart.getChildByName('btn_left');
//节点中添加了button组件 则可以添加click事件监听 // //节点中添加了button组件 则可以添加click事件监听
leftBtnNode.on('click', () => { // leftBtnNode.on('click', () => {
if (!this._cantouch) { // if (!this._cantouch) {
return; // return;
} // }
if (this.curPage == 0) { // if (this.curPage == 0) {
return; // return;
} // }
this.curPage = 0 // this.curPage = 0
this.leftMove(); // this.leftMove();
cc.audioEngine.play(this.audioBtn.clip, false, 0.8) // cc.audioEngine.play(this.audioBtn.clip, false, 0.8)
}) // })
const rightBtnNode = bottomPart.getChildByName('btn_right'); // const rightBtnNode = bottomPart.getChildByName('btn_right');
//节点中添加了button组件 则可以添加click事件监听 // //节点中添加了button组件 则可以添加click事件监听
rightBtnNode.on('click', () => { // rightBtnNode.on('click', () => {
if (!this._cantouch) { // if (!this._cantouch) {
return; // return;
} // }
if (this.curPage == 1) { // if (this.curPage == 1) {
return; // return;
} // }
this.curPage = 1 // this.curPage = 1
this.rightMove(); // this.rightMove();
cc.audioEngine.play(this.audioBtn.clip, false, 0.5) // cc.audioEngine.play(this.audioBtn.clip, false, 0.5)
}) // })
}, // },
leftMove() { // leftMove() {
this._cantouch = false; // this._cantouch = false;
const len = this.pic1.parent.width; // const len = this.pic1.parent.width;
cc.tween(this.pic1) // cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' }) // .to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
.start(); // .start();
cc.tween(this.pic2) // cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' }) // .to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
.call(() => { // .call(() => {
this._cantouch = true; // this._cantouch = true;
}) // })
.start(); // .start();
}, // },
rightMove() { // rightMove() {
this._cantouch = false; // this._cantouch = false;
const len = this.pic1.parent.width; // const len = this.pic1.parent.width;
cc.tween(this.pic1) // cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' }) // .to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
.start(); // .start();
cc.tween(this.pic2) // cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' }) // .to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
.call(() => { // .call(() => {
this._cantouch = true; // this._cantouch = true;
}) // })
.start(); // .start();
}, // },
// update (dt) {}, // update (dt) {},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment