Commit 420775d8 authored by 范雪寒's avatar 范雪寒

feat: 增加星星飞行效果

parent ff4cde55
...@@ -11,27 +11,97 @@ cc.Class({ ...@@ -11,27 +11,97 @@ cc.Class({
properties: { properties: {
}, },
start() { start() {
this.initListeners();
},
initListeners() {
const BtnAddStar = cc.find('Canvas/BtnAddStar');
BtnAddStar.on('click', this.addStar.bind(this));
const BtnShowStar = cc.find('Canvas/BtnShowStar');
BtnShowStar.on('click', this.showStar.bind(this));
},
length,
addStar() {
if (!this.length) {
this.length = 0;
}
this.length++;
let length = this.length;
let length = 0;
setInterval(() => {
const starLayout = cc.find('Canvas/layout'); const starLayout = cc.find('Canvas/layout');
starLayout.removeAllChildren(); starLayout.removeAllChildren();
const paddingY = starLayout.getComponent(cc.Layout).spacingY; const paddingY = starLayout.getComponent(cc.Layout).spacingY;
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
const star = cc.instantiate(cc.find('Star')); const starBase = cc.instantiate(cc.find('StarBase'));
star.name = `star_${i}`; starBase.name = `starBase_${i}`;
star.scale = this.Between(0.5, 1, (starLayout.height / length - paddingY) / star.height); starBase.scale = this.Between(0.5, (starLayout.height / length - paddingY) / starBase.height, 1);
star.parent = starLayout; starBase.parent = starLayout;
} }
length++; this.currentStarIdx = 0;
}, 1000); },
currentStarIdx: null,
showStar() {
if (!this.currentStarIdx) {
this.currentStarIdx = 0;
}
const starBase = cc.find(`Canvas/layout/starBase_${this.currentStarIdx}`);
if (!starBase) {
return;
}
const star = starBase.getChildByName('Star');
const starBig = star.getChildByName('StarBig');
starBig.scale = 1;
star.active = true;
star.scaleX = 0.7 / starBase.scale;
star.scaleY = 1 / starBase.scale;
star.angle = 90;
const canvas = cc.find('Canvas');
const startPos = this.exchangeNodePos(star.parent, canvas, cc.v2(0, -canvas.height / 2));
const middlePos = this.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 / starBase.scale, scaleY: 0.8 / starBase.scale }, { easing: 'quadOut' })
.to(0.1, { y: middlePos.y, scaleX: 1 / starBase.scale, scaleY: 1 / starBase.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();
})
.start();
this.currentStarIdx++;
}, },
Between(a, b, c) { Between(a, b, c) {
return [a, b, c].sort()[1]; return [a, b, c].sort()[1];
}, },
exchangeNodePos(targetNode, baseNode, basePos) {
return targetNode.convertToNodeSpaceAR(baseNode.convertToWorldSpaceAR(cc.v2(basePos.x, basePos.y)));
},
}); });
{
"ver": "2.3.5",
"uuid": "f52d3699-7f54-4afe-ae7e-57ed7fb43ba7",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 278,
"height": 275,
"platformSettings": {},
"subMetas": {
"icon_bigstar": {
"ver": "1.0.4",
"uuid": "b00d89ac-54ee-4b06-878a-acef8c97f0df",
"rawTextureUuid": "f52d3699-7f54-4afe-ae7e-57ed7fb43ba7",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 278,
"height": 275,
"rawWidth": 278,
"rawHeight": 275,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "a3af0e38-26ac-48a5-b033-cdb020817fc9",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 62,
"height": 69,
"platformSettings": {},
"subMetas": {
"icon_star": {
"ver": "1.0.4",
"uuid": "f72965fe-cf21-4551-adcb-6bdc04be67a0",
"rawTextureUuid": "a3af0e38-26ac-48a5-b033-cdb020817fc9",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 62,
"height": 69,
"rawWidth": 62,
"rawHeight": 69,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ 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