var res = { scoreCounter_ex:"res/pancake/a4.png", scoreCounter_0:"res/pancake/a6.png", scoreCounter_1:"res/pancake/a7.png", scoreCounter_2:"res/pancake/a8.png", scoreCounter_3:"res/pancake/a9.png", scoreCounter_4:"res/pancake/aa.png", scoreCounter_5:"res/pancake/ab.png", scoreCounter_6:"res/pancake/ac.png", scoreCounter_7:"res/pancake/ad.png", scoreCounter_8:"res/pancake/ae.png", scoreCounter_9:"res/pancake/af.png", }; var oyumaru = oyumaru || {}; oyumaru.scoreCounter = cc.Layer.extend({ _nOrder:0, _nScore:0, _arrResPath:[ "res/pancake/a6.png", "res/pancake/a7.png", "res/pancake/a8.png", "res/pancake/a9.png", "res/pancake/aa.png", "res/pancake/ab.png", "res/pancake/ac.png", "res/pancake/ad.png", "res/pancake/ae.png", "res/pancake/af.png", ], init:function(nOrder){ this._super(); this._nOrder = nOrder; var spDummy = cc.Sprite.create(this._arrResPath[0]); var spWidth = spDummy.getContentSize().width; var spHeight = spDummy.getContentSize().height; this.setContentSize(spWidth * this._nOrder, spHeight); this.setAnchorPoint(0.0, 0.0); for(var i = 0; i < this._nOrder; i++) { var sp = cc.Sprite.create(this._arrResPath[0]); sp.setPosition(this.getContentSize().width - spWidth/2 - spWidth * i, spHeight/2); this.addChild(sp, i, i); } return true; }, setScore:function(nScore) { this._updateScore(nScore); }, plusScore:function(nPlus) { this._updateScore(this._nScore + nPlus); }, minusScore:function(nMinus) { this._updateScore(this._nScore - nMinus); }, _updateScore:function(nScore) { if(nScore <= 0) nScore = 0; if(nScore > Math.pow(10,this._nOrder)-1) { this._safeAddExclamation(); } else { this._nScore = nScore; this._safeRemoveExclamtion(); } for(var i = 0; i < this._nOrder; i++) { var num = Math.floor(this._nScore / Math.pow(10, i)); num = num % 10; var sp = this.getChildByTag(i); sp.initWithFile(this._arrResPath[num]); } }, _safeAddExclamation:function() { var spExclamation = this.getChildByTag(this._nOrder); if(!spExclamation) { spExclamation = cc.Sprite.create("res/pancake/a4.png"); spExclamation.setPosition(-spExclamation.getContentSize().width/2, spExclamation.getContentSize().height/2); this.addChild(spExclamation, this._nOrder, this._nOrder); } }, _safeRemoveExclamtion:function() { var spExclamation = this.getChildByTag(this._nOrder); if(spExclamation) { spExclamation.removeFromParent(true); } }, }); oyumaru.scoreCounter.create = function(nOrder) { var pRet = new oyumaru.scoreCounter(); if(pRet.init(nOrder)) { return pRet; } return null; };