| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import { _decorator, Component, Node, Vec3, EventHandler, Animation, SpriteFrame, Sprite } from 'cc';
- import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
- import { UITween } from '../core/ui/tween/UITween';
- const { ccclass, property } = _decorator;
- @ccclass('Firework')
- export class Firework extends Component {
- @property({ tooltip: "缓动动画", type: UITween }) private uiTween: UITween;
- // @property({ tooltip: "飘落动画启动回调", type: EventHandler }) private animStartBack: EventHandler[] = [];
- // @property({ tooltip: "飘落动画结束回调", type: EventHandler }) private animEndBack: EventHandler[] = [];
- start() {
- }
- public async playEffect(position: { x: number, y: number }) {
- let imgType = Math.ceil(Math.random() * 7);
- let img = await this.node.getComponent(ResourceLoader).load<SpriteFrame>("image/firework/" + imgType + "/spriteFrame", SpriteFrame);
- this.node.getComponent(Sprite).spriteFrame = img;
- let tempRotation = 360;
- this.uiTween.targetData[0].propsData.position = new Vec3(position.x, position.y);
- this.uiTween.targetData[0].duration = 0.3;
- this.uiTween.targetData[1].propsData.position = new Vec3(position.x, position.y - (180 + Math.random() * 100));
- this.uiTween.targetData[1].propsData.eulerAngles =
- new Vec3((Math.random() - Math.random()) * tempRotation, (Math.random() - Math.random()) * tempRotation, (Math.random() - Math.random()) * tempRotation);
- this.uiTween.targetData[1].duration = Math.random() * 0.5 + 0.5;
- this.scheduleOnce(() => {
- this.uiTween.play();
- })
- }
- public playAnim() {
- this.node.getComponent(Animation).play();
- }
- public endDestory() {
- this.node.destroy();
- }
- }
|