[Edit 4]Nvm I forgot to add:
childInt_id[i] = Integer.parseInt(childString_id[i]);
[Edit 3]So now I want to be able to have a parent entity have multiple children
<entity x="640" y="224" type="gamebutton1" id="1" child_id="2, 3"/>
I'm now parsing child_id as a string, converting it to a string array via .split(","), and converting the string array to an int array
final String child_id = SAXUtils.getAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_CHILD_ID);
String[] childString_id = child_id.split(",");
int[] childInt_id = new int[childString_id.length];
I've declared ChildID in levelObjectUserData into an array
public int[] ChildID = {-1};
And I'm looping through the ButtonSpriteChild array to see if it matches ButtonSpriteID
for (int k = 0; k < ButtonSpriteChild.length; k++){
if (ButtonSpriteChild[k] == ButtonSpriteID){ ... } }
I'm not getting any errors when I run the game, but now no lines are being draw between entities. I wanted to ask if I'm missing anything?
By the way this is how I'm drawing the lines:
float parentX = levelObjects.get(i).getX();
float parentY = levelObjects.get(i).getY();
float childX = levelObjects.get(j).getX();
float childY = levelObjects.get(j).getY();
Line line = new Line(parentX, parentY, childX, childY, 10,vbom);
line.setColor(Color.GREEN);
attachChild(line);
[Edit 2]:Thank you Steve so much for the help! One more thing could please expand a little bit on the last bit of your answer -"Now after your parsing of the XML...", I have trouble understanding your example "((levelObjectUserData) (levelObjects.get(i).getUserData())).ChildID", when I try to use it I get the following error:"Syntax error, insert "AssignmentOperator Expression" to complete Expression". And again thank you so much for your help
[Edit]: I have figured out the first part of my problem some of the entities from the xml file were missing ids and child_ids, and adding those fixed the error.
So my question becomes, how do I use "id" and "child_id" to draw a line between two entities. So once two level objects have been matched I need to get the x and y value of the parent entity and the x and y value of the child entity so that a line can be drawn between them i.e
<entity x="640" y="224" type="gamebutton1" id="1" child_id="2"/>
<entity x="512" y="224" type="gamebutton2" id="2"/>
Line line = new Line(parentX, parentY, childX, childY, 5, vbom);
So this is how I'm parsing the levelObjects
levelLoader.registerEntityLoader(new EntityLoader<SimpleLevelEntityLoaderData>(TAG_ENTITY) {
@Override
public IEntity onLoadEntity(String pEntityName, IEntity pParent, Attributes pAttributes, SimpleLevelEntityLoaderData pEntityLoaderData) throws IOException {
final int x = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_X);
final int y = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_Y);
final String type = SAXUtils.getAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_TYPE);
final int id = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_ID);
final int child_id = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_CHILD_ID);
final ButtonSprite levelObject;
if (type.equals(TAG_ENTITY_ATTRIBUTE_VALUE_GAMEBUTTON1)) {
levelObject = new ButtonSprite(x, y, resourcesManager.gamebutton1_region, vbom, new OnClickListener() {
@Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
}
});
}
else if (type.equals(TAG_ENTITY_ATTRIBUTE_VALUE_GAMEBUTTON2)) {
levelObject = new ButtonSprite(x, y, resourcesManager.gamebutton2_region, resourcesManager.gamebuttonpressed_region, vbom, new OnClickListener() {
@Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
}
});
}
else if (type.equals(TAG_ENTITY_ATTRIBUTE_VALUE_GAMEBUTTON3)) {
levelObject = new ButtonSprite(x, y, resourcesManager.gamebutton3_region, resourcesManager.gamebuttonpressed_region, vbom, new OnClickListener() {
@Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
}
});
}
else if (type.equals(TAG_ENTITY_ATTRIBUTE_VALUE_GAMEBUTTON4)) {
levelObject = new ButtonSprite(x, y, resourcesManager.gamebutton4_region, resourcesManager.gamebuttonpressed_region, vbom, new OnClickListener() {
@Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
}
});
}
else if (type.equals(TAG_ENTITY_ATTRIBUTE_VALUE_GAMEBUTTON5)) {
levelObject = new ButtonSprite(x, y, resourcesManager.gamebutton5_region, resourcesManager.gamebuttonpressed_region, vbom, new OnClickListener() {
@Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
}
});
}
else if (type.equals(TAG_ENTITY_ATTRIBUTE_VALUE_GAMEBUTTON6)) {
levelObject = new ButtonSprite(x, y, resourcesManager.gamebutton6_region, resourcesManager.gamebuttonpressed_region, vbom, new OnClickListener() {
@Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
}
});
}
else {
throw new IllegalArgumentException();
}
levelObject.setCullingEnabled(true);
registerTouchArea(levelObject);
setTouchAreaBindingOnActionDownEnabled(true);
return levelObject;
}
});
And based on that I assume that getting the parent x and y, I would simple use final int x and final int y, but I'm not sure how I would be able to get the child x and y.
I hope I've been able to clarify my problem
See Question&Answers more detail:
os