武器库的建立

//建立武器库的代码
    _buildWeaponWithOb:function(ob){  
        var that = this        
        cc.loader.loadRes("prefab/weapon", function (err, prefab) {            
            //实例化预制件
            var newNode = cc.instantiate(prefab);    
            //添加图片属性        
            that._addSpriteFrameToContainer(newNode.getChildByName('pic').getComponent(cc.Sprite), 
                ob.image)
            //给预制件添加名字的文本框属性
            newNode.getChildByName('name').getComponent(cc.Label).string = ob.name     
            //给预制件添加价格的文本框属性
            newNode.getChildByName('moneyLabel').getComponent(cc.Label).string = ob.price 
            //给预制件添加攻击力的文本框属性
            newNode.getChildByName('attackLabel').getComponent(cc.Label).string = ob.min+"-"+ob.max                            
            //给预制件添加坐标            
            that._position++ 
            // newNode.setPosition(0,0) 
            newNode.setPosition(-40,-that._position * 80)            
            //将预制件添加到NPC对话框中
            that.weaponScrollView.content.addChild(newNode);     
            newNode.getChildByName('buyBtn').on(cc.Node.EventType.TOUCH_START, function (event) {
            that.getComponent('alterCertainPanel').pub_setInfo('确认使用'+ob.price+'购买'+ob.name+"吗?",
                    buyWeapon
                )
                function buyWeapon(){
                    if(GameAction.buyItem (ob.price)){
                        GameData.player.moneyLabel -= ob.price;
                        GameData.player.attackMin = ob.min;
                        GameData.player.attackMax = ob.max;
                    }
                    cc.log('尝试购买')
               }                
            })
                
        });
    },
    _addSpriteFrameToContainer:function(container, name){
        //动态添加图片
        container.spriteFrame = this.loadWaitImage
        cc.loader.loadRes(name, cc.SpriteFrame, function (err, atlas) {
            container.spriteFrame = atlas
            });
    },    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值