gameplay_view.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { _decorator, Component, Node, Size, Sprite, SpriteFrame, UITransform } from 'cc';
  2. import { base_ui } from '../fw/base_ui';
  3. import { tools } from '../tools';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('gameplay_view')
  6. export class gameplay_view extends base_ui {
  7. @property(Node) btn_close:Node = null
  8. @property(Node) content_img:Node = null
  9. protected start(): void {
  10. this.onButtonListen(this.btn_close, ()=>{
  11. this.close()
  12. })
  13. let img_url = tools.sys_config.game_introduction_img
  14. // console.log('img_url=',img_url)
  15. if(img_url.length>0) {
  16. tools.loadRemoteImg(img_url, (r)=>{
  17. this.showContentImg(r.sf)
  18. })
  19. }
  20. }
  21. private showContentImg(sf:SpriteFrame) {
  22. if(sf==null||sf==undefined) {
  23. return
  24. }
  25. let img_width = this.content_img.getComponent(UITransform).contentSize.width
  26. let bili = sf.width / sf.height
  27. let img_height = img_width / bili
  28. let img_size = new Size(img_width, img_height)
  29. this.content_img.getComponent(UITransform).setContentSize(img_size)
  30. this.content_img.getComponent(Sprite).spriteFrame = sf
  31. }
  32. }