平铺的地图对象未显示(无错误)

时间:2018-01-14 09:40:08

标签: android libgdx tiled

此代码工作正常,没有错误,地图加载,但我已经创建了一个创建对象类,它没有创建没有错误的ant对象或正文我认为它创建,但由于某些原因不显示不显示

 public class Screens implements Screen {
        Texture texture;
        MyGdxGame game;
        ObjectCreater objectCreater;
        Player palyer;

   public OrthographicCamera cam;
    Viewport viewport;
   public static TiledMap map;
    TiledMapRenderer tiledMapRenderer;
    World world;
    @Override
    public void show() {
        cam=new OrthographicCamera(400/100,200/100);
        viewport=new StretchViewport(400/100,900/100);
        cam.position.set(1,1,0);

        map=new TmxMapLoader().load("level1.tmx");
        tiledMapRenderer=new OrthogonalTiledMapRenderer(map,1f/100f);
        texture=new Texture("player.png");
        game=new MyGdxGame();

        world=new World(new Vector2(0,-10),true);

        palyer=new Player();
        objectCreater=new ObjectCreater();




    }

    @Override
    public void render(float delta) {
        movecam();
        game.batch.setProjectionMatrix(cam.combined);
        cam.update();
        Gdx.gl.glClearColor(1, 1, 1,1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        tiledMapRenderer.setView(cam);
        tiledMapRenderer.render();

创建对象类我从0开始计数到我在地图中创建的对象 我确定它的4

public class ObjectCreater {
public static Body Groundbody;
World world;
Player player;
MyGdxGame game;
BodyDef grpund;
Screens screens;
public ObjectCreater(){

    screens=new Screens();
    player=new Player();
    game=new MyGdxGame();



    grpund=new BodyDef();
    FixtureDef fixter=new FixtureDef();
    PolygonShape polygonShape=new PolygonShape();



    for (MapObject object:screens.map.getLayers().get(4).getObjects().getByType(RectangleMapObject.class)){
        Rectangle rect = ((RectangleMapObject) object).getRectangle();


        grpund.type= BodyDef.BodyType.StaticBody;
        grpund.position.set(((rect.getX() + rect.getWidth() / 2)/100), (rect.getY() + rect.getHeight() / 2)/100);
        Groundbody= player.world.createBody(grpund);

        polygonShape.setAsBox((rect.getWidth()/2)/100,(rect.getHeight()/2)/100);
        fixter.shape=polygonShape;
        fixter.filter.categoryBits=16;
        Groundbody.createFixture(fixter).setUserData("backw");
    }

1 个答案:

答案 0 :(得分:1)

要绘制box2d实体,您必须创建Box2dDebugRenderer

Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer();

// in render:
debugRenderer.render(world, cam.combined);