Exchange2Layer.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import SoundMgr from "../base/SoundMgr";
  2. import Tool from "../base/Tool";
  3. var baseLayer = require('BaseLayer');
  4. cc.Class({
  5. extends: baseLayer,
  6. properties: {
  7. atlasCoin: cc.SpriteAtlas, //金币图集
  8. itemPrefab: cc.Node,
  9. conNode: cc.Node,
  10. },
  11. // LIFE-CYCLE CALLBACKS:
  12. onLoad () {
  13. this._super();
  14. this.initItems();
  15. },
  16. start () {
  17. },
  18. initItems(){
  19. this.conNode.removeAllChildren();
  20. for(let i=0; i< 7; i++){
  21. let temp = cc.instantiate(this.itemPrefab);
  22. temp.setParent(this.conNode);
  23. temp.name = `${i}`;
  24. temp.active = true;
  25. temp.getChildByName('labCoin').getComponent(cc.Label).string = `${321}万金币`;
  26. temp.getChildByName('sp').getComponent(cc.Sprite).spriteFrame = this.atlasCoin.getSpriteFrame('coin2');
  27. temp.getChildByName('labCi').getComponent(cc.Label).string = `今日剩余兑换${12}次`;
  28. let labNum = cc.find('layout/labNum', temp).getComponent(cc.Label);
  29. labNum.string = `x${333}`;
  30. let labVip = cc.find('btn_orange/labVip', temp).getComponent(cc.Label);
  31. labVip.string = `VIP${3}可兑换`;
  32. let dui = temp.getChildByName('btn_orange');
  33. Tool.addBtnListener(dui, this.node, 'Exchange2Layer', 'onClickExchange', i);
  34. }
  35. },
  36. onClickExchange(event, customEventData){
  37. SoundMgr.playClick();
  38. console.log('customEventData: ', customEventData);
  39. },
  40. });