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

clean code

parent c3534108
......@@ -7,183 +7,166 @@
import { getSprNode } from "../script/util";
cc.Class({
extends: cc.Component,
properties: {
context: {
set: function(ctx) {
this._ctx = ctx;
},
},
extends: cc.Component,
count: {
set: function(count) {
this._count = count;
this.setStarCount();
},
}
// 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;
// }
// },
properties: {
bgHeight: {
set: function (bgHeight) {
this._bgHeight = bgHeight;
},
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start () {
count: {
set: function (count) {
this._count = count;
this.setStarCount();
},
},
setStarCount() {
console.log('set Star Count');
let disH = 80;
// let disScale = 1;
// if (this._count > 5) {
// disH = (400 / gArr.length);
// disScale = 5 / gArr.length;
// }
for (let i=0; i<this._count; i++) {
const starBg = this.getSprNode("img/star_bg")
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();
node.addComponent(cc.Sprite).spriteFrame = sf;
return node;
},
bigStarArr: null,
initStar() {
const gArr = this.data.groupArr;
if (gArr.length <= 1) {
return;
}
this.cleanStar();
this.bigStarArr = [];
let baseX = this.canvas.width / 2 - 80 * this._mapScaleMin;
let baseY = this.canvas.height / 2 - 80 * this._mapScaleMin;
let disH = 80 * this._mapScaleMin;
let disScale = 1;
if (gArr.length > 5) {
disH = (400 / gArr.length) * this._mapScaleMin;
disScale = 5 / gArr.length;
}
for (let i = 0; i < gArr.length; i++) {
const starBg = getSprNode('star_bg');
this.canvas.addChild(starBg, 10);
starBg.x = baseX;
starBg.y = baseY - i * disH;
starBg.scale = disScale;
const starTop = getSprNode('star');
starBg.addChild(starTop);
starTop.active = false;
starBg.star = starTop;
const starBig = getSprNode('icon_bigstar');
starTop.addChild(starBig);
starBig.angle = -90;
starBg.starBig = starBig;
this.bigStarArr.push(starBg);
}
console.log("bigStarArr: ", this.bigStarArr);
},
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];
const starBig = bigStarBg.starBig;
starBig.scale = 1;
const star = bigStarBg.star;
star.active = true;
star.scaleX = 0.7 / bigStarBg.scale;
star.scaleY = 1 / bigStarBg.scale;
star.angle = 90;
const canvas = cc.find('Canvas');
const startPos = exchangeNodePos(star.parent, canvas, cc.v2(0, -canvas.height / 2));
const middlePos = exchangeNodePos(star.parent, canvas, cc.v2(0, -canvas.height / 4));
star.x = startPos.x;
star.y = startPos.y - starBig.height;
console.log('middlePos = ' + JSON.stringify(middlePos));
const time = 1;
cc.tween(star)
.to(0.3, { y: middlePos.y + 80 }, { easing: 'quadOut' })
.to(0.1, { y: middlePos.y + 40, scaleX: 1.2 / bigStarBg.scale, scaleY: 0.8 / bigStarBg.scale }, { easing: 'quadOut' })
.to(0.1, { y: middlePos.y, scaleX: 1 / bigStarBg.scale, scaleY: 1 / bigStarBg.scale }, { easing: 'quadOut' })
.delay(0.1)
.to(0.8, { angle: -720, scale: 1 })
.start();
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();
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) {},
},
start() {},
setStarCount() {
let disH = 80;
// let disScale = 1;
// if (this._count > 5) {
// disH = (400 / gArr.length);
// disScale = 5 / gArr.length;
// }
for (let i = 0; i < this._count; i++) {
const starBg = this.getSprNode("img/star_bg");
starBg.y = -i * disH;
this.node.addChild(starBg);
}
},
getSprNode(resName) {
const sf = cc.find(resName, this.node).getComponent(cc.Sprite).spriteFrame;
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;
}
this.cleanStar();
this.bigStarArr = [];
let baseX = this.canvas.width / 2 - 80 * this._mapScaleMin;
let baseY = this.canvas.height / 2 - 80 * this._mapScaleMin;
let disH = 80 * this._mapScaleMin;
let disScale = 1;
if (gArr.length > 5) {
disH = (400 / gArr.length) * this._mapScaleMin;
disScale = 5 / gArr.length;
}
for (let i = 0; i < gArr.length; i++) {
const starBg = getSprNode("star_bg");
this.canvas.addChild(starBg, 10);
starBg.x = baseX;
starBg.y = baseY - i * disH;
starBg.scale = disScale;
const starTop = getSprNode("star");
starBg.addChild(starTop);
starTop.active = false;
starBg.star = starTop;
const starBig = getSprNode("icon_bigstar");
starTop.addChild(starBig);
starBig.angle = -90;
starBg.starBig = starBig;
this.bigStarArr.push(starBg);
}
console.log("bigStarArr: ", this.bigStarArr);
},
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];
const starBig = bigStarBg.starBig;
starBig.scale = 1;
const star = bigStarBg.star;
star.active = true;
star.scaleX = 0.7 / bigStarBg.scale;
star.scaleY = 1 / bigStarBg.scale;
star.angle = 90;
const canvas = cc.find("Canvas");
const startPos = exchangeNodePos(
star.parent,
canvas,
cc.v2(0, -canvas.height / 2)
);
const middlePos = exchangeNodePos(
star.parent,
canvas,
cc.v2(0, -canvas.height / 4)
);
star.x = startPos.x;
star.y = startPos.y - starBig.height;
console.log("middlePos = " + JSON.stringify(middlePos));
const time = 1;
cc.tween(star)
.to(0.3, { y: middlePos.y + 80 }, { easing: "quadOut" })
.to(
0.1,
{
y: middlePos.y + 40,
scaleX: 1.2 / bigStarBg.scale,
scaleY: 0.8 / bigStarBg.scale,
},
{ easing: "quadOut" }
)
.to(
0.1,
{
y: middlePos.y,
scaleX: 1 / bigStarBg.scale,
scaleY: 1 / bigStarBg.scale,
},
{ easing: "quadOut" }
)
.delay(0.1)
.to(0.8, { angle: -720, scale: 1 })
.start();
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();
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": {
"name": "未知游戏",
"name": "UNKNOW GAME",
"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