[LibGdx][RUBE] Remove images when removing bodies
Posted: Sat Mar 15, 2014 4:31 am
Hi! I'm using LibGdx with Rube, but I'm having trouble removing images when removing a body. The body gets removed, but the Image still stays there. It's probably something I need to do with the loader Im using for LibGdx, but I can't figure out what 
This is how I flag bodies:
Removing the flagged bodies (after the world step):
How it load Spatials (images?):

This is how I flag bodies:
Code: Select all
if(contact.getFixtureA().getBody().getUserData().equals("Player") && contact.getFixtureB().getBody().getUserData().equals("Star") ||
contact.getFixtureB().getBody().getUserData().equals("Player") && contact.getFixtureA().getBody().getUserData().equals("Star")){
starCollected = true;
if(contact.getFixtureA().getBody().getUserData().equals("Star")){
removeBodyList.add(contact.getFixtureA().getBody());
}else if(contact.getFixtureB().getBody().getUserData().equals("Star")){
removeBodyList.add(contact.getFixtureB().getBody());
}
Code: Select all
public void removeBodiesFromList(){
for(int i = removeBodyList.size; i > 0; i--){
box2dWorld.destroyBody(removeBodyList.get(i - 1));
}
removeBodyList.clear();
}
Code: Select all
private void createSpatialsFromRubeImages(RubeScene scene)
{
Array<RubeImage> images = scene.getImages();
if ((images != null) && (images.size > 0))
{
mSpatials = new Array<SimpleSpatial>();
for (int i = 0; i < images.size; i++)
{
RubeImage image = images.get(i);
mTmp.set(image.width, image.height);
String textureFileName = "data/Maps/Graphics/" + image.file;
String[] parts = textureFileName.split("assets/");
textureFileName = parts[1].trim();
Texture texture = mTextureMap.get(parts[1].trim());
if (texture == null){
texture = new Texture(textureFileName);
mTextureMap.put(textureFileName, texture);
}
SimpleSpatial spatial = new SimpleSpatial(texture, image.flip, image.body, image.color, mTmp, image.center,
image.angleInRads * MathUtils.radiansToDegrees);
mSpatials.add(spatial);
}
}
}