//建立武器库的代码
_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
});
},
_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
});
},