GamePage.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import GameItem from "./GameItem";
  2. import { SubLocation } from "./YZ_Constant";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class GamePage extends cc.Component {
  6. _gameList: any = null;
  7. _gameItemNodes: cc.Node[] = [];
  8. _isContentFilled: boolean = false;
  9. _dataDirty: boolean = false;
  10. public init(data: any) {
  11. this._gameList = data;
  12. this._dataDirty = true;
  13. }
  14. onLoad() {
  15. this._gameItemNodes = this.node.children;
  16. for (let i = 0; i < this._gameItemNodes.length; i++) {
  17. this._gameItemNodes[i].active = false;
  18. }
  19. }
  20. update(dt: number) {
  21. if (this._dataDirty) {
  22. this._dataDirty = false;
  23. this._updateContent();
  24. }
  25. }
  26. _updateContent() {
  27. if (this._gameList && this._gameList.length > 0 && this._gameList.length <= 5) {
  28. this._isContentFilled = true;
  29. let itemData = null;
  30. for (let i = 0; i < this._gameList.length; i++) {
  31. itemData = this._gameList[i];
  32. let newGameItemNode: cc.Node = this._gameItemNodes[i];
  33. let gameItem: GameItem = newGameItemNode.getComponent("GameItem");
  34. gameItem.init(itemData, SubLocation.isScrollbar);
  35. newGameItemNode.active = true;
  36. }
  37. }
  38. }
  39. }