RoleCard.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { _decorator, Component, Label, Node, Sprite } from 'cc';
  2. import { resMgr } from '../../Frames/ResourcesMgr';
  3. import { RoleData } from '../../DataItem/ItemData';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('RoleCard')
  6. export class RoleCard extends Component {
  7. typeRole: Node = null;
  8. roleImg: Node = null;
  9. atk: Node = null;
  10. atkLength: Node = null;
  11. hp: Node = null;
  12. moveSpeed: Node = null;
  13. data: RoleData = null;
  14. protected onLoad(): void {
  15. this.typeRole = this.node.getChildByName("Types_of_Role");
  16. this.roleImg = this.node.getChildByName("Role_Img");
  17. this.atk = this.node.getChildByPath("Attribute/Atk");
  18. this.hp = this.node.getChildByPath("Attribute/Hp");
  19. this.atkLength = this.node.getChildByPath("Attribute/AtkLength");
  20. this.moveSpeed = this.node.getChildByPath("Attribute/MoveSpeed");
  21. }
  22. protected start(): void {
  23. }
  24. init(id: number, data: RoleData[]){
  25. this.typeRole.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(data[id].typeRole);
  26. this.roleImg.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(data[id].imgName);
  27. this.atk.getComponent(Label).string = `攻 击:${data[id].atk}` ;
  28. this.hp.getComponent(Label).string = `血 量:${data[id].hp}` ;
  29. this.atkLength.getComponent(Label).string = `攻击距离:${data[id].atkLength}` ;
  30. this.moveSpeed.getComponent(Label).string = `移动速度:${data[id].moveSpeed}` ;
  31. }
  32. //是否打开或者关闭Shadow
  33. //初始时Shadow是关闭的 true -> 打开 false -> 关闭
  34. isOpenShadow(open: boolean){
  35. this.node.getChildByName("Shadow").active = open;
  36. }
  37. //获取Shadow的active false -> 关闭 true -> 打开
  38. getShadowState(){
  39. return this.node.getChildByName("Shadow").active;
  40. }
  41. getRoleImgName(): string{
  42. return this.roleImg.getComponent(Sprite).spriteFrame.name;
  43. }
  44. }