import { _decorator, Component, SpriteFrame,Node, ParticleSystem } from 'cc'; import { eventEmitter } from '../../core/event/EventEmitter'; import { Constants } from '../../data/Constants'; const { ccclass, property } = _decorator; @ccclass('GunBase') export class GunBase extends Component { @property({type: Node,tooltip:"枪口节点"}) public muzzleNode: Node = null! public data: any = null;//枪的数据 public isFire: boolean = false;//是否在开火状态 public endCb: Function = null;//结束回调 public bulletSF: SpriteFrame = null!;//子弹贴图 需要的替换贴图的设置 //射击出去的子弹数 private _shotBullets: number = 0; public set shotBullets(value: number) { this._shotBullets = value; eventEmitter.dispatch(Constants.eventName.magazine_num_change); } public get shotBullets() { return this._shotBullets; } constructor(){ super(); this.isFire = false; this.endCb = null; } init(data: any,holder: any,endCb?: Function,ammoCb?: Function){ } /**开火*/ fire(){ } endFire(){ } /** * 播放粒子特效 * @param node 粒子节点 */ public playParticle(node:Node){ node.getComponentsInChildren(ParticleSystem) .forEach(e => { e.stop(); e.play(); }); } }