Commit 731980ed authored by Seaborn Lee's avatar Seaborn Lee

clean code

parent c3534108
...@@ -7,183 +7,166 @@ ...@@ -7,183 +7,166 @@
import { getSprNode } from "../script/util"; import { getSprNode } from "../script/util";
cc.Class({ cc.Class({
extends: cc.Component, extends: cc.Component,
properties: {
context: {
set: function(ctx) {
this._ctx = ctx;
},
},
count: { properties: {
set: function(count) { bgHeight: {
this._count = count; set: function (bgHeight) {
this.setStarCount(); this._bgHeight = bgHeight;
}, },
}
// foo: {
// // ATTRIBUTES:
// default: null, // The default value will be used only when the component attaching
// // to a node for the first time
// type: cc.SpriteFrame, // optional, default is typeof default
// serializable: true, // optional, default is true
// },
// bar: {
// get () {
// return this._bar;
// },
// set (value) {
// this._bar = value;
// }
// },
}, },
// LIFE-CYCLE CALLBACKS: count: {
set: function (count) {
// onLoad () {}, this._count = count;
this.setStarCount();
start () { },
}, },
},
setStarCount() {
console.log('set Star Count'); start() {},
let disH = 80; setStarCount() {
// let disScale = 1; let disH = 80;
// if (this._count > 5) { // let disScale = 1;
// disH = (400 / gArr.length); // if (this._count > 5) {
// disScale = 5 / gArr.length; // disH = (400 / gArr.length);
// } // disScale = 5 / gArr.length;
// }
for (let i=0; i<this._count; i++) {
const starBg = this.getSprNode("img/star_bg") for (let i = 0; i < this._count; i++) {
starBg.y= -i * disH; const starBg = this.getSprNode("img/star_bg");
this.node.addChild(starBg); starBg.y = -i * disH;
} this.node.addChild(starBg);
}, }
},
setContext(ctx) {
getSprNode(resName) {
}, const sf = cc.find(resName, this.node).getComponent(cc.Sprite).spriteFrame;
const node = new cc.Node();
getSprNode(resName) { node.addComponent(cc.Sprite).spriteFrame = sf;
const sf = cc.find(resName, this.node).getComponent(cc.Sprite).spriteFrame; return node;
const node = new cc.Node(); },
node.addComponent(cc.Sprite).spriteFrame = sf;
return node; bigStarArr: null,
}, initStar() {
const gArr = this.data.groupArr;
if (gArr.length <= 1) {
return;
bigStarArr: null, }
initStar() {
const gArr = this.data.groupArr; this.cleanStar();
if (gArr.length <= 1) {
return; this.bigStarArr = [];
}
let baseX = this.canvas.width / 2 - 80 * this._mapScaleMin;
this.cleanStar(); let baseY = this.canvas.height / 2 - 80 * this._mapScaleMin;
let disH = 80 * this._mapScaleMin;
this.bigStarArr = []; let disScale = 1;
if (gArr.length > 5) {
let baseX = this.canvas.width / 2 - 80 * this._mapScaleMin; disH = (400 / gArr.length) * this._mapScaleMin;
let baseY = this.canvas.height / 2 - 80 * this._mapScaleMin; disScale = 5 / gArr.length;
let disH = 80 * this._mapScaleMin; }
let disScale = 1; for (let i = 0; i < gArr.length; i++) {
if (gArr.length > 5) { const starBg = getSprNode("star_bg");
disH = (400 / gArr.length) * this._mapScaleMin; this.canvas.addChild(starBg, 10);
disScale = 5 / gArr.length; starBg.x = baseX;
} starBg.y = baseY - i * disH;
for (let i = 0; i < gArr.length; i++) { starBg.scale = disScale;
const starBg = getSprNode('star_bg');
this.canvas.addChild(starBg, 10); const starTop = getSprNode("star");
starBg.x = baseX; starBg.addChild(starTop);
starBg.y = baseY - i * disH; starTop.active = false;
starBg.scale = disScale; starBg.star = starTop;
const starTop = getSprNode('star'); const starBig = getSprNode("icon_bigstar");
starBg.addChild(starTop); starTop.addChild(starBig);
starTop.active = false; starBig.angle = -90;
starBg.star = starTop; starBg.starBig = starBig;
const starBig = getSprNode('icon_bigstar'); this.bigStarArr.push(starBg);
starTop.addChild(starBig); }
starBig.angle = -90;
starBg.starBig = starBig; console.log("bigStarArr: ", this.bigStarArr);
},
this.bigStarArr.push(starBg);
} cleanStar() {
if (this.bigStarArr && this.bigStarArr.length > 0) {
console.log("bigStarArr: ", this.bigStarArr); for (let i = 0; i < this.bigStarArr.length; i++) {
}, this.bigStarArr[i].removeFromParent();
}
cleanStar() { }
if (this.bigStarArr && this.bigStarArr.length > 0) { },
for (let i=0; i<this.bigStarArr.length; i++) {
this.bigStarArr[i].removeFromParent(); showBigStar() {
} if (!this.bigStarArr || this.bigStarArr.length <= 0) {
} // this.checkGameEnd();
}, return;
}
const bigStarBg = this.bigStarArr[this.curGroupIndex];
showBigStar() {
if (!this.bigStarArr || this.bigStarArr.length <= 0) { const starBig = bigStarBg.starBig;
// this.checkGameEnd(); starBig.scale = 1;
return; const star = bigStarBg.star;
} star.active = true;
const bigStarBg = this.bigStarArr[this.curGroupIndex]; star.scaleX = 0.7 / bigStarBg.scale;
star.scaleY = 1 / bigStarBg.scale;
const starBig = bigStarBg.starBig; star.angle = 90;
starBig.scale = 1; const canvas = cc.find("Canvas");
const star = bigStarBg.star; const startPos = exchangeNodePos(
star.active = true; star.parent,
star.scaleX = 0.7 / bigStarBg.scale; canvas,
star.scaleY = 1 / bigStarBg.scale; cc.v2(0, -canvas.height / 2)
star.angle = 90; );
const canvas = cc.find('Canvas'); const middlePos = exchangeNodePos(
const startPos = exchangeNodePos(star.parent, canvas, cc.v2(0, -canvas.height / 2)); star.parent,
const middlePos = exchangeNodePos(star.parent, canvas, cc.v2(0, -canvas.height / 4)); canvas,
star.x = startPos.x; cc.v2(0, -canvas.height / 4)
star.y = startPos.y - starBig.height; );
star.x = startPos.x;
console.log('middlePos = ' + JSON.stringify(middlePos)); star.y = startPos.y - starBig.height;
const time = 1;
cc.tween(star) console.log("middlePos = " + JSON.stringify(middlePos));
.to(0.3, { y: middlePos.y + 80 }, { easing: 'quadOut' }) const time = 1;
.to(0.1, { y: middlePos.y + 40, scaleX: 1.2 / bigStarBg.scale, scaleY: 0.8 / bigStarBg.scale }, { easing: 'quadOut' }) cc.tween(star)
.to(0.1, { y: middlePos.y, scaleX: 1 / bigStarBg.scale, scaleY: 1 / bigStarBg.scale }, { easing: 'quadOut' }) .to(0.3, { y: middlePos.y + 80 }, { easing: "quadOut" })
.delay(0.1) .to(
.to(0.8, { angle: -720, scale: 1 }) 0.1,
.start(); {
y: middlePos.y + 40,
cc.tween(star) scaleX: 1.2 / bigStarBg.scale,
.delay(0.6) scaleY: 0.8 / bigStarBg.scale,
.to(0.8, { x: 0 }, { easing: 'quadIn' }) },
.start(); { easing: "quadOut" }
cc.tween(star) )
.delay(0.6) .to(
.to(0.8, { y: 0 }, { easing: 'quadOut' }) 0.1,
.start(); {
y: middlePos.y,
cc.tween(starBig) scaleX: 1 / bigStarBg.scale,
.delay(0.6) scaleY: 1 / bigStarBg.scale,
.to(0.8, { scale: 0 }, { easing: 'quadOut' }) },
.call(() => { { easing: "quadOut" }
// this.checkGameEnd(); )
// playAudio(this.starCountClip); .delay(0.1)
}) .to(0.8, { angle: -720, scale: 1 })
.start(); .start();
// playAudio(this.bigStarClip); cc.tween(star).delay(0.6).to(0.8, { x: 0 }, { easing: "quadIn" }).start();
}, cc.tween(star).delay(0.6).to(0.8, { y: 0 }, { easing: "quadOut" }).start();
// update (dt) {}, cc.tween(starBig)
.delay(0.6)
.to(0.8, { scale: 0 }, { easing: "quadOut" })
.call(() => {
// this.checkGameEnd();
// playAudio(this.starCountClip);
})
.start();
// playAudio(this.bigStarClip);
},
// update (dt) {},
}); });
This diff is collapsed.
{ {
"game": { "game": {
"name": "未知游戏", "name": "UNKNOW GAME",
"appid": "UNKNOW" "appid": "UNKNOW"
} }
} }
\ No newline at end of file
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