I am doing this in java, but the answer isn’t java specific.
Here is my code:
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++;
}
}
As you can see, for every “x” in the map string, I want to create a new platform. Now, each line of the string is 57 characters long, and I need to get the X and Y value of where that X is, but all I can retrieve is the charAt the “i” variable, in the for statement. What is a logical way to do this?
…where
%is modulo and/is integer division.