Commit 5a6afb6e authored by 范雪寒's avatar 范雪寒

feat: 新增一个撒花效果

parent 420775d8
......@@ -177,7 +177,7 @@
"array": [
0,
0,
791.547219058977,
700.831058012557,
0,
0,
0,
......
This diff is collapsed.
{
"ver": "1.2.7",
"uuid": "960a9be8-b5a8-4ad7-8457-12d6f06588a2",
"asyncLoadAssets": false,
"autoReleaseAssets": true,
"subMetas": {}
}
\ No newline at end of file
// Learn cc.Class:
// - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { asyncDelay, RandomInt } from "../script/utils";
cc.Class({
extends: cc.Component,
properties: {
},
start() {
this.initView();
},
initView() {
const bg = cc.find('Canvas/bg');
bg.on('touchstart', async (event) => {
const pos = bg.convertToNodeSpaceAR(event.getLocation());
this.showOneFirework(pos, bg, cc.find('paperBase').children);
});
const btn = cc.find('Canvas/BtnShow');
btn.on('click', () => {
this.showAllFirework(bg, cc.find('paperBase').children);
});
},
async showOneFirework(pos, parentNode, nodeList) {
for (let i = 0; i < 3; i++) {
this.showFirework(pos, parentNode, nodeList);
await asyncDelay(0.1);
}
},
async showAllFirework(parentNode, nodeList) {
for (let i = 0; i < 6; i++) {
this.showFirework(cc.v2(0, -parentNode.height / 2), parentNode, nodeList, parentNode.width * 1, parentNode.height * 2);
await asyncDelay(0.1);
}
},
showFirework(pos, parentNode, nodeList, width = 200, height = 200) {
for (let i = 0; i < 30; i++) {
const quad = this.createQuads(pos, parentNode, nodeList);
const targetX = RandomInt(width / 2, -width / 2);
cc.tween(quad)
.to(5, { x: pos.x + targetX * 7 })
.start();
cc.tween(quad)
.to(0.5, { y: pos.y + RandomInt(height) }, { easing: 'quadOut' })
.to(2, { y: -parentNode.height * 2 }, { easing: 'quadIn' })
.removeSelf()
.start();
}
},
createQuads(pos, parentNode, nodeList) {
const quadBase = cc.instantiate(nodeList[RandomInt(nodeList.length)]);
quadBase.x = pos.x;
quadBase.y = pos.y;
quadBase.z = pos.z;
quadBase.angle = RandomInt(90);
quadBase.parent = parentNode;
const quad = quadBase.getChildByName('quad');
quad.x = 0;
quad.y = 0;
quad.angle = RandomInt(90);
const paper = quad.getChildByName('paper');
paper.scaleX = Math.random() * 0.5 + 0.5;
paper.scaleY = Math.random() * 0.5 + 0.5;
quadBase.scaleX = Math.random();
cc.tween(quadBase)
.to((1 - quadBase.scaleX) * 0.3, { scaleX: 1 })
.call(() => {
const time = Math.random() * 0.2;
cc.tween(quadBase)
.to(0.1 + time, { scaleX: -1 })
.to(0.1 + time, { scaleX: 1 })
.union()
.repeatForever()
.start();
})
.start();
return quadBase;
},
});
{
"ver": "1.0.8",
"uuid": "29f1b6f8-b69f-4f93-91bd-97cf20d3c07f",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -44,6 +44,9 @@ cc.Class({
}, {
sceneName: 'demo_02_scoreStars',
label: '星星'
}, {
sceneName: 'demo_03_fireworks_2',
label: '翻转撒花'
}];
demoList.forEach((demoItem, idx) => {
......
{
"ver": "1.0.8",
"uuid": "d07c22c6-ea88-491a-8716-e509d7265361",
"isPlugin": false,
"isPlugin": true,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
......
{
"ver": "2.3.5",
"uuid": "5bd403c0-9676-4b25-8b82-b8bba1f11db1",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 29,
"height": 29,
"platformSettings": {},
"subMetas": {
"Img_paper": {
"ver": "1.0.4",
"uuid": "9b6f7e88-adc2-446f-b791-1259c116637c",
"rawTextureUuid": "5bd403c0-9676-4b25-8b82-b8bba1f11db1",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 29,
"height": 29,
"rawWidth": 29,
"rawHeight": 29,
"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