12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { _decorator, Component, Label, Node, Sprite } from 'cc';
- import { resMgr } from '../../Frames/ResourcesMgr';
- import { RoleData } from '../../DataItem/ItemData';
- const { ccclass, property } = _decorator;
- @ccclass('RoleCard')
- export class RoleCard extends Component {
- typeRole: Node = null;
- roleImg: Node = null;
- atk: Node = null;
- atkLength: Node = null;
- hp: Node = null;
- moveSpeed: Node = null;
- data: RoleData = null;
- protected onLoad(): void {
- this.typeRole = this.node.getChildByName("Types_of_Role");
- this.roleImg = this.node.getChildByName("Role_Img");
- this.atk = this.node.getChildByPath("Attribute/Atk");
- this.hp = this.node.getChildByPath("Attribute/Hp");
- this.atkLength = this.node.getChildByPath("Attribute/AtkLength");
- this.moveSpeed = this.node.getChildByPath("Attribute/MoveSpeed");
- }
- protected start(): void {
-
- }
- init(id: number, data: RoleData[]){
- this.typeRole.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(data[id].typeRole);
- this.roleImg.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(data[id].imgName);
- this.atk.getComponent(Label).string = `攻 击:${data[id].atk}` ;
- this.hp.getComponent(Label).string = `血 量:${data[id].hp}` ;
- this.atkLength.getComponent(Label).string = `攻击距离:${data[id].atkLength}` ;
- this.moveSpeed.getComponent(Label).string = `移动速度:${data[id].moveSpeed}` ;
- }
- //是否打开或者关闭Shadow
- //初始时Shadow是关闭的 true -> 打开 false -> 关闭
- isOpenShadow(open: boolean){
- this.node.getChildByName("Shadow").active = open;
- }
- //获取Shadow的active false -> 关闭 true -> 打开
- getShadowState(){
- return this.node.getChildByName("Shadow").active;
- }
- getRoleImgName(): string{
- return this.roleImg.getComponent(Sprite).spriteFrame.name;
- }
- }
|