SHARE
TWEET

Untitled

a guest Mar 24th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.badlogic.gdx.Gdx;
  2. import com.badlogic.gdx.maps.MapObject;
  3. import com.badlogic.gdx.maps.MapObjects;
  4. import com.badlogic.gdx.maps.objects.RectangleMapObject;
  5. import com.badlogic.gdx.maps.tiled.TiledMap;
  6. import com.badlogic.gdx.math.Rectangle;
  7. import com.badlogic.gdx.math.Vector2;
  8. import com.badlogic.gdx.physics.box2d.Body;
  9. import com.badlogic.gdx.physics.box2d.BodyDef;
  10. import com.badlogic.gdx.physics.box2d.PolygonShape;
  11. import com.badlogic.gdx.physics.box2d.Shape;
  12. import com.badlogic.gdx.physics.box2d.World;
  13.  
  14. public class ConvertidorMapa
  15. {
  16.     private static final float TAM_BLOQUE = 1;
  17.  
  18.  
  19.     public static void crearCuerpos(TiledMap mapa, World mundo) {
  20.         MapObjects objetos = mapa.getLayers().get("paredes").getObjects();
  21.         Gdx.app.log("MAPA", "cantidad objetos: " + objetos.getCount());
  22.         for (MapObject objeto: objetos) {
  23.             Shape rectangulo = getRectangle((RectangleMapObject)objeto);
  24.  
  25.             BodyDef bd = new BodyDef();
  26.             bd.position.set(((RectangleMapObject) objeto).getRectangle().x, ((RectangleMapObject) objeto).getRectangle().y);
  27.             bd.type = BodyDef.BodyType.StaticBody;
  28.             Body body = mundo.createBody(bd);
  29.             body.createFixture(rectangulo, 1);
  30.  
  31.             rectangulo.dispose();
  32.         }
  33.     }
  34.  
  35.     private static PolygonShape getRectangle(RectangleMapObject objeto) {
  36.         Rectangle rectangulo = objeto.getRectangle();
  37.         PolygonShape polygon = new PolygonShape();
  38.  
  39.         Vector2 tam = new Vector2((rectangulo.width*0.5f)/TAM_BLOQUE,
  40.                 ( rectangulo.height*0.5f)/TAM_BLOQUE);
  41.  
  42.         polygon.setAsBox(rectangulo.width*0.5f/TAM_BLOQUE, rectangulo.height*0.5f/TAM_BLOQUE, tam, 0f);
  43.         return polygon;
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top