Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //My contact listener
- @Override
- public void beginContact(Contact contact){
- Fixture fa = contact.getFixtureA();
- Fixture fb = contact.getFixtureB();
- //The if statement that never works...
- if(fb.getUserData() == "door") System.out.println("Collided with door.");
- }
- //where the userdata gets set for the objects
- public static void mapColl(){
- MapLayer l = Play.currentMap.getLayers().get("Collision");
- for(MapObject m : l.getObjects()){
- BodyDef bdef = new BodyDef();
- bdef.type = BodyType.StaticBody;
- Body b = Play.world.createBody(bdef);
- 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);
- PolygonShape shape = new PolygonShape();
- shape.setAsBox(m.getProperties().get("width", Float.class) / 2, m.getProperties().get("height", Float.class) / 2);
- FixtureDef fdef = new FixtureDef();
- fdef.shape = shape;
- Fixture f = b.createFixture(fdef);
- f.setUserData(m.getProperties().get("type", String.class));
- shape.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement