IsometricTiledMapRenderer Box2d碰撞检测MapObject

时间:2015-06-25 12:04:41

标签: java libgdx box2d

我正在尝试渲染等距平铺地图,例如,如果我使用OrthogonalTiledMapRenderer进行正交平铺地图box2dObjects/bodies在完成MapObjects初始化的代码后呈现完美:

if (object instanceof RectangleMapObject) {
                RectangleMapObject rectangleObj = (RectangleMapObject)object;
                Rectangle rectangle = rectangleObj.getRectangle();
                position= new Vector2((rectangle.x+rectangle.getWidth()*0.5f)/Game.SCALE_PIXELS_ToMETERS, (rectangle.y+rectangle.getHeight()*0.5f)/Game.SCALE_PIXELS_ToMETERS);
                size= new Vector2(rectangle.getWidth()/Game.SCALE_PIXELS_ToMETERS, rectangle.getHeight()/Game.SCALE_PIXELS_ToMETERS);
                PolygonShape polygon = new PolygonShape();
                polygon.setAsBox(rectangle.width * 0.5f / Game.SCALE_PIXELS_ToMETERS,rectangle.height * 0.5f / Game.SCALE_PIXELS_ToMETERS);
                shape=polygon;
            }
            else if (object instanceof PolygonMapObject) {
                PolygonMapObject polygonObj = (PolygonMapObject)object;
                PolygonShape polygon = new PolygonShape();
                float[] vertices = polygonObj.getPolygon().getTransformedVertices();
                float[] worldVertices = new float[vertices.length];
                for (int i = 0; i < vertices.length; ++i) {
                    worldVertices[i] = vertices[i] / Game.SCALE_PIXELS_ToMETERS;
                }
                polygon.set(worldVertices);
                shape=polygon;
                position=null;

            }
            else if (object instanceof PolylineMapObject) {
                PolylineMapObject polyLineObj = (PolylineMapObject)object;
                Polyline polyLine=polyLineObj.getPolyline();
                position= new Vector2(polyLineObj.getPolyline().getX(),polyLineObj.getPolyline().getY());
                //vector=scaleToMeters(vector,polyLine.getLength(),polyLineObj.height);
                shape = getPolyline((PolylineMapObject)object);
            }
            else if (object instanceof CircleMapObject) {
                CircleMapObject circleObj = (CircleMapObject)object;
                Circle circle = circleObj.getCircle();
                CircleShape circleShape = new CircleShape();
                circleShape.setRadius(circle.radius / Game.SCALE_PIXELS_ToMETERS);
                circleShape.setPosition(new Vector2(circle.x / Game.SCALE_PIXELS_ToMETERS, circle.y / Game.SCALE_PIXELS_ToMETERS));
                position= new Vector2(circle.x,circle.y);
                shape = circleShape;
            }


            Entity entity=null;
            if(object.getName().equals("StaticWall")) entity=createStaticWallObject(shape,object.getName(),object,position); 
            if(entity!=null) dynamicEntitys.add(entity);    

一切运作完美 - &gt;&gt;

enter image description here

但如果我尝试使用IsometricTiledMapRenderer并使用debug mode:on运行它,我会遇到以下问题:

enter image description here

但我不希望mapobjects成为Orthogonal!

enter image description here

0 个答案:

没有答案