FPanel.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import FSprite from "./FSprite";
  2. /**
  3. * 面板数据显示
  4. */
  5. const {ccclass, property} = cc._decorator;
  6. @ccclass
  7. export default class FPanel extends cc.Component {
  8. @property(cc.ProgressBar)
  9. mHPBar: cc.ProgressBar = null;
  10. @property(cc.Label)
  11. mLabel: cc.Label = null;
  12. public sprite:FSprite;
  13. onLoad () {
  14. this.sprite = this.node.parent.getComponent(FSprite);
  15. if(this.mLabel){
  16. this.mLabel.string = '';
  17. }
  18. }
  19. /**
  20. * 更新当前面板
  21. */
  22. public updatePanel(){
  23. if(this.sprite){
  24. this.mHPBar.progress = this.sprite.hp/this.sprite.attrData.hp;
  25. if(this.mLabel){
  26. this.mLabel.string = this.sprite.hp+'/'+this.sprite.attrData.hp;
  27. }
  28. if(this.sprite.hp <= 0){
  29. this.node.active = false;
  30. }else{
  31. this.node.active = true;
  32. }
  33. }
  34. }
  35. public setCancel(){
  36. if(this.sprite &&this.sprite.isValid &&this.sprite.attrData.type != 2){
  37. this.node.stopAllActions();
  38. cc.tween(this.node).sequence(
  39. cc.delayTime(2),
  40. cc.callFunc(()=>{
  41. this.node.active = false;
  42. })
  43. ).start();
  44. }
  45. }
  46. public setClose(){
  47. this.node.active = false;
  48. }
  49. }