43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
// Learn TypeScript:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
|
|
// Learn Attribute:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
|
|
|
|
const {ccclass, property} = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class ParticleEffect extends cc.Component {
|
|
|
|
private isSubTime:boolean = false;
|
|
private playTime:number = 0;
|
|
private particle:cc.ParticleSystem = null;
|
|
onLoad(){
|
|
this.particle = this.node.getComponent<cc.ParticleSystem>(cc.ParticleSystem);
|
|
}
|
|
|
|
setInfo(pos:cc.Vec2,playTime:number,showColor:cc.Color = null){
|
|
this.isSubTime = true;
|
|
this.playTime = playTime
|
|
this.node.position = pos;
|
|
if(showColor != null){
|
|
this.particle.startColor = showColor;
|
|
this.particle.endColor = showColor;
|
|
}
|
|
}
|
|
update (dt) {
|
|
if(this.isSubTime){
|
|
this.playTime = this.playTime - dt;
|
|
if(this.playTime <= 0){
|
|
this.isSubTime = false
|
|
this.node.destroy();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|