Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用badlogic框架编写一个方法来迭代要打印的数字?_Java_Android - Fatal编程技术网

Java 如何使用badlogic框架编写一个方法来迭代要打印的数字?

Java 如何使用badlogic框架编写一个方法来迭代要打印的数字?,java,android,Java,Android,我用badlogic的Mr.Nom框架创建了一个游戏。如何遍历每个字符并打印分数?帮助。尝试一下:对所有数字使用单独的区域 public void drawText(String line, float x, int y) { int len = line.length(); batcher.beginBatch(Assets.numbers); for (int i = 0; i < len; i++) { char character = lin

我用badlogic的Mr.Nom框架创建了一个游戏。如何遍历每个字符并打印分数?帮助。

尝试一下:对所有数字使用单独的区域

public void drawText(String line, float x, int y) {
    int len = line.length();
    batcher.beginBatch(Assets.numbers);
    for (int i = 0; i < len; i++) {
        char character = line.charAt(i);

        if (character == ' ') {
            x += 20;
            continue;
        }

        int srcX = 0;
        int srcWidth = 0;
        if (character == '.') {
            srcX = 200;
            srcWidth = 10;
        } else {
            srcX = (character - '0') * 20;
            srcWidth = 20;
        }


        if(character=='0')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.zeroRegion);
        if(character=='1')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.oneRegion);
     if(character=='2')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.twoRegion);
         if(character=='3')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.threeRegion);
         if(character=='4')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.fourRegion);
         if(character=='5')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.fiveRegion);
         if(character=='6')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.sixRegion);
         if(character=='7')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.sevenRegion);
         if(character=='8')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.eightRegion);
         if(character=='9')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.nineRegion);
         if(character=='.')
            batcher.drawSprite(x, y, srcWidth, 32, Assets.dotRegion);

        x += srcWidth;
    }
    batcher.endBatch();
}
public void drawText(字符串行、浮点x、整数y){
int len=line.length();
batcher.beginBatch(资产编号);
对于(int i=0;i
请向我们展示您的代码。这将使我们更容易帮助你。谢谢@Rob。得到答案了吗