private void processFreeBodies(Array<MapObject> bodies) { for (MapObject object : bodies) { FixtureBodyDefinition fixtureBodyDefinition; if (object instanceof RectangleMapObject) { fixtureBodyDefinition = TiledUtils.createRectangleFixtureBodyDef((RectangleMapObject)object); } else if (object instanceof CircleMapObject) { fixtureBodyDefinition = TiledUtils.createCircleFixtureBodyDef((CircleMapObject)object); } else if (object instanceof EllipseMapObject) { fixtureBodyDefinition = TiledUtils.createEllipseFixtureBodyDef((EllipseMapObject)object); } else if (object instanceof PolylineMapObject || object instanceof PolygonMapObject) { fixtureBodyDefinition = TiledUtils.createPolyFixtureBodyDef(object); } else { throw new InvalidConfigException(filename, "Unknown MapObject type"); } freeBodyDefinitions.add(fixtureBodyDefinition); } }
public static FixtureDef getFixtureDefFromBodySkeleton(MapObject object) { FixtureDef fixtureDef = new FixtureDef(); fixtureDef.density = 1; fixtureDef.friction = 0; fixtureDef.restitution = 0; Shape shape = null; if (object instanceof TextureMapObject) { shape = getTextureMapShape(object); } else if (object instanceof RectangleMapObject) { shape = getRectangleShape(object); } else if (object instanceof CircleMapObject) { shape = getCircleShape(object); } else if (object instanceof EllipseMapObject) { shape = getEllipseShape(object); } else if (object instanceof PolygonMapObject) { shape = getPolygonShape(object); } else if (object instanceof PolylineMapObject) { shape = getPolylineShape(object); } fixtureDef.shape = shape; return fixtureDef; }
private Vector2 getPositionFromMapObject(MapObject mapObject) { if (mapObject instanceof PolygonMapObject) { Polygon polygon = ((PolygonMapObject) mapObject).getPolygon(); return new Vector2(polygon.getX(), polygon.getY()); } else if (mapObject instanceof RectangleMapObject) { Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); return new Vector2(rectangle.getX(), rectangle.getY()); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); return new Vector2(ellipse.x, ellipse.y); } else if (mapObject instanceof CircleMapObject) { Circle circle = ((CircleMapObject) mapObject).getCircle(); return new Vector2(circle.x, circle.y); } throw new GdxRuntimeException("Only Polygons, Rectangles, Ellipses and Circles are supported!"); }
public static FixtureBodyDefinition createCircleFixtureBodyDef(CircleMapObject object) { BodyDef bodyDef = new BodyDef(); Circle circle = object.getCircle(); bodyDef.position.x = circle.x; bodyDef.position.y = circle.y; bodyDef.position.scl(MainCamera.getInstance().getTileMapScale()); bodyDef.type = getBodyType(object); FixtureDef fixtureDef = getFixtureDefFromBodySkeleton(object); return new FixtureBodyDefinition(fixtureDef, bodyDef); }
private static Shape getCircleShape(MapObject object) { Circle circle = ((CircleMapObject)object).getCircle(); CircleShape shape = new CircleShape(); shape.setRadius(circle.radius * MainCamera.getInstance().getTileMapScale()); return shape; }
private Shape getCircle(CircleMapObject circleObject) { Circle circle = circleObject.getCircle(); CircleShape circleShape = new CircleShape(); circleShape.setRadius(circle.radius / GameWorld.units); circleShape.setPosition(new Vector2(circle.x / GameWorld.units, circle.y / GameWorld.units)); return circleShape; }
private Shape getCircle(CircleMapObject circleObject) { Circle circle = circleObject.getCircle(); CircleShape circleShape = new CircleShape(); circleShape.setRadius(circle.radius / units); circleShape.setPosition(new Vector2(circle.x / units, circle.y / units)); return circleShape; }
private Shape getCircle(CircleMapObject circleObject) { Circle circle = circleObject.getCircle(); CircleShape circleShape = new CircleShape(); circleShape.setRadius(circle.radius * m_units); circleShape.setPosition(new Vector2(circle.x * m_units, circle.y * m_units)); return circleShape; }
private void crearColisiones() { Array<Body> slopes = new Array<Body>(); FixtureDef fixDef = new FixtureDef(); MapObjects objects = cls.getObjects(); Iterator<MapObject> objectIt = objects.iterator(); while(objectIt.hasNext()) { MapObject object = objectIt.next(); if (object instanceof TextureMapObject){ continue; } Shape shape; BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; if (object instanceof RectangleMapObject) { RectangleMapObject rectangle = (RectangleMapObject)object; shape = getRectangle(rectangle); } else if (object instanceof PolygonMapObject) { shape = getPolygon((PolygonMapObject)object); } else if (object instanceof PolylineMapObject) { shape = getPolyline((PolylineMapObject)object); } else if (object instanceof EllipseMapObject) { shape = getEllipse((EllipseMapObject)object); } else if (object instanceof CircleMapObject) { shape = getCircle((CircleMapObject)object); } else { continue; } fixDef.shape = shape; fixDef.filter.categoryBits = GameWorld.BIT_PARED; fixDef.filter.maskBits = GameWorld.BIT_JUGADOR | GameWorld.BIT_ENEMIGOS | GameWorld.BIT_SENSOR; Body suelo = GameWorld.mundo.createBody(bodyDef); suelo.createFixture(fixDef).setUserData("cls"); slopes.add(suelo); shape.dispose(); } }
/** * @param map map to be used to create the static bodies. * @param layerName name of the layer that contains the shapes. */ public void createPhysics(Map map, String layerName) { MapLayer layer = map.getLayers().get(layerName); if (layer == null) { logger.error("layer " + layerName + " does not exist"); return; } MapObjects objects = layer.getObjects(); Iterator<MapObject> objectIt = objects.iterator(); while(objectIt.hasNext()) { MapObject object = objectIt.next(); if (object instanceof TextureMapObject){ continue; } Shape shape; BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; if (object instanceof RectangleMapObject) { RectangleMapObject rectangle = (RectangleMapObject)object; shape = getRectangle(rectangle); } else if (object instanceof PolygonMapObject) { shape = getPolygon((PolygonMapObject)object); } else if (object instanceof PolylineMapObject) { shape = getPolyline((PolylineMapObject)object); } else if (object instanceof CircleMapObject) { shape = getCircle((CircleMapObject)object); } else { logger.error("non suported shape " + object); continue; } MapProperties properties = object.getProperties(); String material = properties.get("material", "default", String.class); FixtureDef fixtureDef = materials.get(material); if (fixtureDef == null) { logger.error("material does not exist " + material + " using default"); fixtureDef = materials.get("default"); } fixtureDef.shape = shape; fixtureDef.filter.categoryBits = Env.game.getCategoryBitsManager().getCategoryBits("level"); Body body = world.createBody(bodyDef); body.createFixture(fixtureDef); bodies.add(body); fixtureDef.shape = null; shape.dispose(); } }