PVPBullet.ts 1.4 KB

123456789101112131415161718192021222324252627282930
  1. import { _decorator, Component, Node, Sprite, SpriteFrame, sp, Vec3, v3, tween } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { ConfigData } from '../data/ConfigData';
  4. import { PVPCardData } from './PVP';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('PVPBullet')
  7. export class PVPBullet extends Component {
  8. @property({ type: Sprite, tooltip: "子弹精灵" }) bulletSprite: Sprite;
  9. @property({ type: [SpriteFrame], tooltip: "子弹精灵合集" }) bulletSpriteList: Array<SpriteFrame> = [];
  10. @property({ type: sp.Skeleton, tooltip: "spine组件" }) spine: sp.Skeleton;
  11. @property({ type: [sp.SkeletonData], tooltip: "受击特效合集" }) hitEffectList: Array<sp.SkeletonData> = [];
  12. private spData: sp.SkeletonData;
  13. public setData(data: PVPCardData, dir: number, to: Vec3, cb: Function): void {
  14. this.spData = this.hitEffectList[DataSystem.getData(ConfigData)["general"][data.id]["hit_res"] - 1];
  15. this.bulletSprite.spriteFrame = this.bulletSpriteList[DataSystem.getData(ConfigData)["general"][data.id]["atk_res"] - 1];
  16. this.bulletSprite.node.setScale(v3(dir, 1, 1));
  17. tween(this.node).to(0.3, { position: to }).call(async () => {
  18. if (cb) {
  19. cb();
  20. }
  21. this.bulletSprite.node.active = false;
  22. this.spine.skeletonData = this.spData;
  23. this.spine.setAnimation(0, "animation", false);
  24. }).start();
  25. }
  26. }