| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { _decorator, Component, Node, Prefab, instantiate, UITransform, math, tween, Vec3, SpriteFrame, Sprite } from 'cc';
- import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
- import { LineLightPk } from './LineLightPk';
- import { ParliclePk } from './ParliclePk';
- const { ccclass, property } = _decorator;
- @ccclass('AddParliclePkBase')
- export class AddParliclePkBase extends Component {
- @property({ tooltip: "粒子特效父级,不填写默认当前node", type: Node }) public parlicleBox: Node;
- @property({ tooltip: "底图", type: Sprite }) public seatLight: Sprite;
- @property({ tooltip: "底图", type: Sprite }) public leader: Sprite;
- public type = 1;
- start() {
- if (!this.parlicleBox) {
- this.parlicleBox = this.node;
- }
- }
- /**
- * 设置图片资源
- * @param type 0:红色底座光球,1:蓝色底座光球
- */
- public async setData(type: number) {
- this.type = type;
- if (type != 1) {
- let img: SpriteFrame = await ResourcesUtils.load("Images/rolesBase/leader" + type + "/spriteFrame", SpriteFrame, this.node);
- this.leader.spriteFrame = img;
- let img0: SpriteFrame = await ResourcesUtils.load("Images/rolesBase/seatLight" + type + "/spriteFrame", SpriteFrame, this.node);
- this.seatLight.spriteFrame = img;
- }
- this.addParlicle();
- this.addLineLight();
- this.schedule(this.addParlicle, 0.2)
- this.schedule(this.addLineLight, 0.25)
- }
- public async addParlicle() {
- let times = Math.ceil(Math.random() * 5);
- for (let i = 0; i < times; i++) {
- let prefab = await ResourcesUtils.load<Prefab>("Prefabs/SpecialEffects/粒子光效pk底座", Prefab, this.node);
- let parlicle = instantiate(prefab);
- parlicle.parent = this.parlicleBox;
- parlicle.getComponent(ParliclePk).setImag(this.type);
- let _w = this.parlicleBox.getComponent(UITransform).width - 20;
- let _h = this.parlicleBox.getComponent(UITransform).height;
- let _x = _w / 2 - (_w * Math.random());
- let _y = -_h / 2 * Math.random();
- let endX = _x + ((Math.random() - Math.random()) * 100);
- let endY = _h / 2 * Math.random();
- parlicle.setPosition(new Vec3(_x, _y));
- let _scale = Math.random() * 0.5 + 0.5;
- parlicle.setScale(new Vec3(_scale, _scale));
- let t = tween(parlicle);
- t.to(0.65, { position: new Vec3(endX, endY) }).start();
- }
- }
- public async addLineLight() {
- let times = Math.ceil(Math.random() * 6);
- for (let i = 0; i < times; i++) {
- let prefab = await ResourcesUtils.load<Prefab>("Prefabs/SpecialEffects/光线特效", Prefab, this.node);
- let lineLight = instantiate(prefab);
- lineLight.parent = this.parlicleBox;
- lineLight.getComponent(LineLightPk).setImag(this.type);
- let _w = this.parlicleBox.getComponent(UITransform).width - 50;
- let _h = this.parlicleBox.getComponent(UITransform).height;
- let _x = _w / 2 - (_w * Math.random());
- let _y = -_h / 2 + 30;
- let endY = _h / 2 * Math.random();
- lineLight.setPosition(new Vec3(_x, _y));
- let t = tween(lineLight);
- t.to(0.65, { position: new Vec3(_x, endY) }).start();
- }
- }
- }
|