GameItem.ts 886 B

1234567891011121314151617181920212223242526272829303132
  1. import { AppKernel } from '@scripts/app/AppKernel';
  2. import { IGameInfo } from '@scripts/store/pageSlice/data';
  3. import { _decorator, Component, Node, Sprite } from 'cc';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('GameItem')
  6. export class GameItem extends Component {
  7. @property(Sprite)
  8. gameIcon: Sprite;
  9. private _gameConfig: IGameInfo;
  10. protected onLoad(): void {
  11. this.node.on(Node.EventType.TOUCH_END, this.onClick, this);
  12. }
  13. protected onDestroy(): void {
  14. this.node.off(Node.EventType.TOUCH_END, this.onClick, this);
  15. }
  16. public async initView(game: IGameInfo) {
  17. this._gameConfig = game;
  18. const resLoader = AppKernel.resources;
  19. this.gameIcon.spriteFrame = await resLoader.loadRemoteSp(game.img);
  20. }
  21. private onClick() {
  22. AppKernel.services.lobbyService.openGame(this._gameConfig.id);
  23. }
  24. }