Advertisement
Guest User

halp

a guest
Apr 28th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. //My contact listener  
  2. @Override
  3. public void beginContact(Contact contact){
  4.     Fixture fa = contact.getFixtureA();
  5.     Fixture fb = contact.getFixtureB();
  6.     //The if statement that never works... 
  7.     if(fb.getUserData() == "door") System.out.println("Collided with door.");
  8. }
  9.  
  10. //where the userdata gets set for the objects
  11. public static void mapColl(){
  12.         MapLayer l = Play.currentMap.getLayers().get("Collision");
  13.         for(MapObject m : l.getObjects()){
  14.             BodyDef bdef = new BodyDef();
  15.             bdef.type = BodyType.StaticBody;
  16.             Body b = Play.world.createBody(bdef);
  17.             b.setTransform(new Vector2(m.getProperties().get("x", Float.class) + (m.getProperties().get("width", Float.class) / 2), m.getProperties().get("y", Float.class) + ((float)m.getProperties().get("height", Float.class) / 2)), 0);
  18.             PolygonShape shape = new PolygonShape();
  19.             shape.setAsBox(m.getProperties().get("width", Float.class) / 2, m.getProperties().get("height", Float.class) / 2);
  20.             FixtureDef fdef = new FixtureDef();
  21.             fdef.shape = shape;
  22.             Fixture f = b.createFixture(fdef);
  23.             f.setUserData(m.getProperties().get("type", String.class));
  24.             shape.dispose();
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement