我在更新的方法来显示我的场均得分增加CCLabel。结果它的工作原理以及之前的分数提高到5000之后的logcat显示messege:
I added CCLabel in my update method to display my game score. It works well before score raise to 5000. After that logCat shows the messege:
02-08 11:47:37.476: E/dalvikvm-heap(4190): 1048576-byte external allocation too large for this process.
02-08 11:47:37.476: E/dalvikvm(4190): Out of memory: Heap Size=14343KB, Allocated=13585KB, Bitmap Size=2078KB
java.lang.reflect.InvocationTargetException......
caused by java.lang.OutOfMemoryError
我的code是:
countScore++ ;
Log.e("total Score:", "" + countScore);
CCLabel labelScore = CCLabel.makeLabel("" + countScore, "DroidSans", 20);
labelScore.setColor(new ccColor3B(1,1,1));
labelScore.setPosition(CGPoint.ccp(50, 50));
addChild(labelScore, 11);
labelScore.setTag(11);
_labelScores.add(labelScore);
CCCallFuncN actionMoveDone1 = CCCallFuncN.action(this, "labelFinished");
CCSequence action = CCSequence.actions(actionMoveDone1);
labelScore.runAction(action);
如何解决?
我认为你正在创建CCLabel每次当你需要。
I think you are creating CCLabel every time when you need.
CCLabel labelScore = CCLabel.makeLabel("" + countScore, "DroidSans", 20);
labelScore.setColor(new ccColor3B(1,1,1));
labelScore.setPosition(CGPoint.ccp(50, 50));
addChild(labelScore, 11);
labelScore.setTag(11);
不要那样做。结果设置您的ScoreLable为全局变量并完成构造函数初始化,颜色设置和定位。在你的病情只能使用以下code。
Don't do that. Set your ScoreLable as global variable and complete its initialization, color setting and positioning in constructor. In your condition use only following code.
labelScore.setString("" + countScore);