gameplay_view.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. console.log(r.sf.width,r.sf.height)
  19. })
  20. }
  21. }
  22. private showContentImg(sf:SpriteFrame) {
  23. if(sf==null||sf==undefined) {
  24. return
  25. }
  26. let img_width = this.content_img.getComponent(UITransform).contentSize.width
  27. let bili = sf.width / sf.height
  28. let img_height = img_width / bili
  29. let img_size = new Size(img_width, img_height)
  30. this.content_img.getComponent(UITransform).setContentSize(img_size)
  31. this.content_img.getComponent(Sprite).spriteFrame = sf
  32. }
  33. }