Изменение значение объекта
Crafty.c('Unit', { facing : 2, name : "TestUnit", face : "Monkey", vitals : { hp : 50, mp : 100, maxhp : 100, maxmp : 100, delay : 500 }, tileX : function() { return this.x/16; }, tileY : function() { return this.y/16; }, newUnit: function(newname,param) { this.name = newname; this.instance = this; if(param){ for(var p in param){//alert(p); var o=p.split(".");//alert(o[0]) if((o[0] in this) && (o[1] in this[o[0]])) this[o[0]][o[1]]=param[p]; } } this.bind("Click", function() { UnitControl.selectUnit(this.instance); }) } }); Создаем персонажа так: UnitControl.createNewUnit(2,2, "Monk1") UnitControl.createNewUnit(3,3, "Monk2",{"vitals.hp":90}); Не пойму, почему имя изменяется правильно (1й персонаж monk1, 2й monk2), то параметр hp меняется у обоих |
Часовой пояс GMT +3, время: 12:05. |