//分数写到本地( 当前分 最高分 历史记录)
updateScore: function() {
var currentScore = this.scoreDisplay.string;
var scoreData = {
'score':currentScore,
'time': D.common.timeFmt(new Date(),'yyyy-MM-dd hh:mm:ss'),
};
var preData = cc.sys.localStorage.getItem('score');
var preTopScore = cc.sys.localStorage.getItem('topScore');
if (!preTopScore || parseInt(preTopScore) < parseInt(currentScore)){
cc.sys.localStorage.setItem('topScore', currentScore);
}
if(!preData){
preData = [];
preData.unshift(scoreData);
} else {
preData = JSON.parse(preData);
if (!(preData instanceof Array)){
preData = [];
}
preData.unshift(scoreData);
}
cc.sys.localStorage.setItem('currentScore', currentScore);
cc.sys.localStorage.setItem('score', JSON.stringify(preData));
},
//获取本地存储的值
//读取最高分和这次的得分
var _topScore = cc.sys.localStorage.getItem('topScore');
this.topScore.string = _topScore;
var _currentScore = cc.sys.localStorage.getItem('currentScore');
this.currentScore.string = _currentScore;