ShopLayer.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import SoundMgr from "../base/SoundMgr";
  2. import Tool from "../base/Tool";
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. atlasCoin: cc.SpriteAtlas, //金币图集
  7. itemPrefab: cc.Node,
  8. conNode: cc.Node,
  9. },
  10. // LIFE-CYCLE CALLBACKS:
  11. onLoad () {
  12. this.initItems();
  13. },
  14. start () {
  15. },
  16. showShop(hallSceneJs){
  17. this.hallSceneJs = hallSceneJs;
  18. this.node.active = true;
  19. },
  20. initItems(){
  21. this.conNode.removeAllChildren();
  22. for(let i=0; i < 6; i++){
  23. let temp = cc.instantiate(this.itemPrefab);
  24. temp.setParent(this.conNode);
  25. temp.name = `item${i}`;
  26. temp.active = true;
  27. temp.getChildByName('labBuy').getComponent(cc.Label).string = '111';
  28. temp.getChildByName('icon').getComponent(cc.Sprite).spriteFrame = this.atlasCoin.getSpriteFrame('coin2');
  29. temp.getChildByName('labGive').getComponent(cc.Label).string = `+${22}万`;
  30. cc.find('btn_yellow/labY', temp).getComponent(cc.Label).string = `¥${60}`;
  31. let xx = temp.getChildByName('btn_yellow');
  32. Tool.addBtnListener(xx, this.node, 'ShopLayer', 'onClickY', i);
  33. }
  34. },
  35. onClickY(event, customEventData){
  36. console.log('customEventData: ', customEventData);
  37. },
  38. onClose(){
  39. SoundMgr.playClick();
  40. this.node.active = false;
  41. this.hallSceneJs.showHides(true);
  42. },
  43. });