UI_Head_Icon.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { _decorator, Component, Node, Size, Sprite, SpriteFrame, UITransform } from 'cc';
  2. import { Hall } from '../../hall/Hall';
  3. import { ch } from 'db://assets/ch/ch';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('UI_Head_Icon')
  6. export class UI_Head_Icon extends Component {
  7. @property(Sprite)//头像
  8. Headicon: Sprite = null;
  9. @property([SpriteFrame])
  10. Head_Skin: SpriteFrame[] = [];
  11. show(uid: string, head: string | null): void {
  12. const rc = this.Head_Skin[ parseInt(uid)%4];
  13. Hall.getInstance().head_icon.showIcon(uid, head, this.Headicon, rc).then((spf)=>{
  14. if(spf != null)
  15. this.adaptationIcon(this.Headicon, spf, new Size(57,57));
  16. });
  17. }
  18. adaptationIcon(icon: Sprite, spriteFrameIcon: SpriteFrame, tSize: Size) {
  19. if (spriteFrameIcon) {
  20. let size = spriteFrameIcon.originalSize
  21. //适配图片
  22. let iconSize = new Size()
  23. let raito = size.width / size.height
  24. if (raito < 1) {
  25. iconSize.height = tSize.height
  26. iconSize.width = tSize.height * raito
  27. } else {
  28. iconSize.width = tSize.width
  29. iconSize.height = tSize.width / raito
  30. }
  31. icon.spriteFrame = spriteFrameIcon
  32. icon.getComponent(UITransform).setContentSize(iconSize)
  33. }
  34. }
  35. }