Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LibGDX tileMap-don';无法检测碰撞_Java_Android_Libgdx_Collision Detection_Tiled - Fatal编程技术网

Java LibGDX tileMap-don';无法检测碰撞

Java LibGDX tileMap-don';无法检测碰撞,java,android,libgdx,collision-detection,tiled,Java,Android,Libgdx,Collision Detection,Tiled,首先,对不起,因为我的英语太生疏了。自从我学了德语,我就忘了英语 我正在用libGDX进行测试,我的代码没有检测到任何冲突 在我的屏幕中: public Pantalla(SpriteBatch batch_1) { batch = batch_1; screenWidth = Gdx.graphics.getWidth(); screenHeight = Gdx.graphics.getHeight(); stage =

首先,对不起,因为我的英语太生疏了。自从我学了德语,我就忘了英语

我正在用libGDX进行测试,我的代码没有检测到任何冲突

在我的屏幕中:

    public Pantalla(SpriteBatch batch_1) {
        batch = batch_1;
        screenWidth = Gdx.graphics.getWidth();
        screenHeight = Gdx.graphics.getHeight();

        stage = new Stage(new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()),batch);
        Gdx.input.setInputProcessor(stage);

        camera = new OrthographicCamera();
        camera.setToOrtho(false, 1000, 840);
        camera.update();

        mapas =  new Mapas(camera);

        //              ACTORS 
        indiana_actor = new indiana_Actor();

    //Here comes TOUCHPAD with Skin blaBlaBla...
     if (touchpad.isTouched()) {  
              if (touchpad.getKnobX() > 120) {
                            indiana_actor.moveBy(32,0);
                            camera.translate(32, 0);
                            return; }
}

stage.addActor(indiana_actor);
            stage.addActor(touchpad);
            Gdx.input.setInputProcessor(stage);
}



    public void render(float delta) {//TODO RENDER
         Gdx.gl.glClearColor(0, 0, 0, 1);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


            mapas.MapasRender(camera,indiana_actor);
            batch.begin();
        batch.end();

        stage.act(Gdx.graphics.getDeltaTime());
        stage.draw();

    }
印第安纳大学演员班:

 public indiana_Actor() {
        W=Gdx.graphics.getWidth(); H=Gdx.graphics.getHeight();
        bounds=new Rectangle((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight());

    }
    Animation anim_temp;


    @Override
    public void draw(Batch batch, float parentAlpha) {
        stateTime += Gdx.graphics.getDeltaTime();
        batch.setColor(getColor());
batch.draw(Assets.indiana_stop_arriba, (W/2), (H/2), 110, 160);

        bounds=new Rectangle((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight());

    }
和Mapas类。 在这些类中,我获取“objetos”平铺层中的对象,并在渲染器中进行三元化以检查与for(…)的冲突

public Mapas(OrthographicCamera camera2){
    map = new TmxMapLoader().load("terrain/prueba.tmx");
    renderer = new OrthogonalTiledMapRenderer(map, 10);//ESCALA
    renderer.setView(camera2);

    collisionObjects = map.getLayers().get("objetos").getObjects();
    collisionRects = new Array<Rectangle>();
    collisionRects_total=collisionObjects.getCount();
    int tileWidth = 32; // whatever your tile width is
    int tileHeight = 32; // whatever your tile height is
    for (int i = 0; i < collisionObjects.getCount(); i++) {
        RectangleMapObject obj = (RectangleMapObject) collisionObjects.get(i);
        Rectangle rect = obj.getRectangle();
        collisionRects.add(new Rectangle(rect.x / tileWidth, rect.y / tileHeight, rect.width / tileWidth, rect.height / tileHeight));
    }


}
public void MapasRender(OrthographicCamera camera2,indiana_Actor indi){
    camera2.update();
    renderer.setView(camera2);
    renderer.render();

    for (int i = 0; i < collisionRects_total; i++) {
        Rectangle rect = collisionRects.get(i);
        if (indi.bounds.overlaps(rect)){
            Gdx.app.log("EVENTO", "MAPAS RENDER - COLISION!");
        }if (rect.overlaps(indi.bounds)){
            Gdx.app.log("EVENTO", "MAPAS RENDER - COLISION!");
        }
    }
} 
公共地图(正交摄影机摄影机2){
map=newtmxmaploader().load(“地形/prueba.tmx”);
渲染器=新的正交平铺贴图渲染器(贴图,10);//ESCALA
渲染器.setView(camera2);
collisionObjects=map.getLayers().get(“objetos”).getObjects();
collisionRects=新数组();
collisionRects_total=collisionObjects.getCount();
int tileWidth=32;//无论平铺宽度是多少
int tileHeight=32;//无论平铺高度是多少
对于(int i=0;i
我(通过日志)知道 对于(int i=0;i 这是演员边界矩形的问题吗?在地图中移动演员时的问题


提前谢谢!!

为什么不先检查一下你的碰撞矩形画的位置是否正确。你可以打电话

  shapeRenderer.begin(ShapeType.Line);
  shapeRenderer.setColor(Color.NAVY);

  shapeRenderer.rect(object.getrect().x,
 object.getrect().y,object.getrect().width,
  object.getrect().height);
可能是您在错误的位置绘制了碰撞矩形,所以碰撞永远不会发生