| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- //钻石
- var diamondInfo = cc.Class({
- name: "diamondInfo",
- properties: {
- diamondSprite: {
- default: null,
- type: cc.SpriteFrame,
- },
- diamondPrice: {
- default: -1,
- type: cc.Integer,
- },
- }
- });
- cc.Class({
- extends: cc.Component,
- properties: {
- diamondItem: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- diamondContent: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- diamondInfos: {
- default: [],
- type: [diamondInfo]
- },
- //支付部分
- playHead: {
- default: null,
- type: cc.Sprite,
- },
- playPrice: {
- default: null,
- type: cc.Label,
- },
- playEdit: {
- default: null,
- type: cc.EditBox,
- },
- PlayNode:cc.Node
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start() {
- for (let index = 0; index < this.diamondInfos.length; index++) {
- // const element = array[index];
- let diamondItem = cc.instantiate(this.diamondItem);
- diamondItem.active = true;
- diamondItem.parent = this.diamondContent;
- diamondItem.getChildByName('MainSprite').getComponent(cc.Sprite).spriteFrame = this.diamondInfos[index].diamondSprite;
- diamondItem.getChildByName('num').getComponent(cc.Label).string = 'x' + this.diamondInfos[index].diamondPrice * 10;
- var clickEventHandler = new cc.Component.EventHandler();
- clickEventHandler.target = this.node;
- clickEventHandler.component = "GameShop";//这个是脚本文件名
- clickEventHandler.handler = "onBuyDiamond"; //回调函名称
- clickEventHandler.customEventData = this.diamondInfos[index].diamondPrice; //用户数据
- var button = diamondItem.getChildByName('buybutton').getComponent(cc.Button); //获取cc.Button组件
- button.node.getChildByName('Label').getComponent(cc.Label).string = this.diamondInfos[index].diamondPrice + '元';
- button.clickEvents.push(clickEventHandler); //增加处理
- }
- //如果存在用户信息
- if (G.userInfo == null) return;
- let _url = G.userInfo.avatarUrl;
- //显示头像
- cc.loader.load({ url: _url, type: 'jpg' }, function (err, texture) {
- var frame = new cc.SpriteFrame(texture);
- if (err) {
- console.log('支付的头像:', err);
- }
-
- this.playHead.getComponent(cc.Sprite).spriteFrame = frame;
- }.bind(this));
-
- },
- onOpenShop(){
- this.node.active = true;
- },
- onCloseShop(){
- this.node.active = false;
- },
- onBuyDiamond(event, data) {
- console.log('购买数目:', data);
- //开启支付页面
- this.onOpenPlay({price:data})
- },
- onOpenPlay(data){
- this.PlayNode.active = true;
- this.playPrice.string = data.price+'.00';
- },
- onClosePlay(){
- this.PlayNode.active = false;
- },
- //更改密码宽度
- onChangePassWord() {
- // console.log('密码改变:', this.playEdit.string);
- // let string = this.playEdit.string;
- // let currentArray = string.split('');
- // let endstring = '';
- // for (let index = 0; index < currentArray.length; index++) {
- // const element = currentArray[index];
- // endstring += ' ' + element;
- // }
- // this.playEdit.string = endstring;
- },
- // update (dt) {},
- });
|