大家好日子, 我有一个小问题,通常会在其他字符串中添加很多不同的字符串,特别是在LibGDX中,最好的方法是什么?
blockString=new StringBuilder(blockString).append(String.valueOf(blockCount.length/2+i)).append("][").append(String.valueOf(f)).append("]").append(String.valueOf(t)).toString();
我必须在尽可能短的时间内完成这个方法几百次。有没有人有想法在Android上的LibGdx中最有效的方法呢?
提前感谢答案
修改
整个循环:
for (int i=-300;i<300;i++){
//whole world Generation(taking up nearly no time)
int f=0;
int max=50;
while (f<max){
if (blockCount[blockCount.length/2+i][0][0]==32&&blockCount[blockCount.length/2+i][0][1]==0){
max=f;
}
if (!(blockCount[blockCount.length/2+i][f][0]==32&&blockCount[blockCount.length/2+i][f][1]==0)){
int t=codeTexture(blockCount[blockCount.length/2+i][f][0],blockCount[blockCount.length/2+i][f][1]);
blockString=blockString.concat("["+String.valueOf(blockCount.length/2+i)+"]"+"["+String.valueOf(f)+"]"+String.valueOf(t));
}
if ((blockCount[blockCount.length/2+i][f][0]==48&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==32&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==0&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==0&&blockCount[blockCount.length/2+i][f][1]==0)||(blockCount[blockCount.length/2+i][f][0]==16&&blockCount[blockCount.length/2+i][f][1]==16)){
max=f+10;
}
f=f+1;
}
}
答案 0 :(得分:0)
您编写的代码与更直接的代码完全相同
blockString += (blockCount.length / 2 + i) + "][" + t;
编辑:要在循环中执行此操作,您的代码应该看起来像
StringBuilder blockStringBuilder = new StringBuilder();
for (int i=-300;i<300;i++){
//whole world Generation(taking up nearly no time)
int f=0;
int max=50;
while (f<max){
if (blockCount[blockCount.length/2+i][0][0]==32&&blockCount[blockCount.length/2+i][0][1]==0){
max=f;
}
if (!(blockCount[blockCount.length/2+i][f][0]==32&&blockCount[blockCount.length/2+i][f][1]==0)){
int t=codeTexture(blockCount[blockCount.length/2+i][f][0],blockCount[blockCount.length/2+i][f][1]);
blockStringBuilder.append("[").append(blockCount.length/2+i).append("][").append(f).append("]").append(t);
}
if ((blockCount[blockCount.length/2+i][f][0]==48&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==32&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==0&&blockCount[blockCount.length/2+i][f][1]==64)||(blockCount[blockCount.length/2+i][f][0]==0&&blockCount[blockCount.length/2+i][f][1]==0)||(blockCount[blockCount.length/2+i][f][0]==16&&blockCount[blockCount.length/2+i][f][1]==16)){
max=f+10;
}
f=f+1;
}
}
blockString = blockStringBuilder.toString();