[LibGdx][RUBE] Remove images when removing bodies

General discussion about the R.U.B.E editor
Post Reply
MayoNinja
Posts: 2
Joined: Sat Mar 15, 2014 4:15 am

[LibGdx][RUBE] Remove images when removing bodies

Post by MayoNinja »

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:

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());
	            	}
Removing the flagged bodies (after the world step):

Code: Select all

public void removeBodiesFromList(){
		for(int i = removeBodyList.size; i > 0; i--){
			box2dWorld.destroyBody(removeBodyList.get(i - 1));
		}
		
		removeBodyList.clear();
	}
How it load Spatials (images?):

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);
		            
		           
	         }
	      }
	   }
MayoNinja
Posts: 2
Joined: Sat Mar 15, 2014 4:15 am

Re: [LibGdx][RUBE] Remove images when removing bodies

Post by MayoNinja »

I noticed that on android version it removes after a certain time (5-6 secs). :)
Post Reply