String 如何从1点得到X和Y?

String 如何从1点得到X和Y?,string,coordinates,String,Coordinates,我是用java做这件事的,但答案不是java特有的 这是我的密码: String map = " x " + " x o xxxx xxxx xxxx " + " x xxxx

我是用java做这件事的,但答案不是java特有的

这是我的密码:

    String map = "                                                   x    " +
                 "     x o                          xxxx   xxxx   xxxx    " +
                 "     x                       xxxx                       " +
                 "     xxxx               xxxx                            " +
                 "         xx      xxxxxx                                 " +
                 "           xx                                           " +
                 "             xx                                         " +
                 "               xx                                  x    " +
                 "                 xx                                x    " +
                 "                   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ";

    for(int i = 0; i < map.length(); i++) {
        if(map.charAt(i) == 'x') {
            platform[i] = CCSprite.sprite("platform_2.gif");
            platform[i].setPosition(x, y); //How to get x and y?
            addChild(platform[i]);
            platformCount++;
        }
    }
String map=“x”+
“x o xxxx xxxx xxxx”+
“x xxxx”+
“xxxx xxxx”+
“xx xxxxxx”+
“xx”+
“xx”+
“xx x”+
“xx x”+
“XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”;
对于(int i=0;i
正如您所看到的,对于映射字符串中的每个“x”,我想创建一个新平台。现在,字符串的每一行都有57个字符长,我需要得到X所在位置的X和Y值,但我能检索到的只是for语句中“I”变量的字符。这样做的逻辑方法是什么

int x = i % width;
int y = i / width;

…其中
%
是且
/
是。

若要添加一些详细信息-
%
是模,并且
/
必须是截断除法。@icktoofay由于某些原因无法工作;左上角的所有平台都乱七八糟corner@Qasim:也许将X和Y坐标乘以精灵的大小。@icktoofay我现在觉得很愚蠢。我以前有过,但一旦我开始使用string方法,我就忘了添加它。谢谢