Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.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问题_Java_Android_Libgdx - Fatal编程技术网

Java 视口/摄影机/渲染的Libgdx问题

Java 视口/摄影机/渲染的Libgdx问题,java,android,libgdx,Java,Android,Libgdx,在过去的两天里,我很难找出我的申请有什么问题。我正在尝试建立一个游戏,一个玩家需要上升的平台(有点像doodlejump)。我已经用tmx格式构建了我的测试图。我一直在尝试启动相机和视口来显示世界的左下角,这样玩家可以向右移动,也可以向上移动。但对于刚开始学习libgdx的人来说,这似乎很难 我正在使用一个播放屏幕、一个HUD和一个主活动: 播放屏幕 private MainActivity game; private OrthographicCamera gamecam; private Vi

在过去的两天里,我很难找出我的申请有什么问题。我正在尝试建立一个游戏,一个玩家需要上升的平台(有点像doodlejump)。我已经用tmx格式构建了我的测试图。我一直在尝试启动相机和视口来显示世界的左下角,这样玩家可以向右移动,也可以向上移动。但对于刚开始学习libgdx的人来说,这似乎很难

我正在使用一个播放屏幕、一个HUD和一个主活动:

播放屏幕

private MainActivity game;
private OrthographicCamera gamecam;
private Viewport gameport;
private HUD hud;

private TmxMapLoader mapLoader;
private TiledMap map;
private OrthogonalTiledMapRenderer renderer;

private World world;
private Box2DDebugRenderer b2dr;

private Jack player;



public PlayScreen(MainActivity game){

    // Initiates the game, camera, viewport and HUD
    this.game = game;
    gamecam = new OrthographicCamera();
    hud = new HUD(game.batch);

    gameport = new FitViewport(MainActivity.V_WIDTH, MainActivity.V_HEIGHT, gamecam);

    // loading the map
    mapLoader = new TmxMapLoader();
    map = mapLoader.load("level1revised.tmx");
    renderer = new OrthogonalTiledMapRenderer(map, 1 / MainActivity.PPM);

    //initially set our gamecam to be centered correctly at the start of of map
    gamecam.position.set(gameport.getWorldWidth() / 2, gameport.getWorldHeight() / 2, 0);

    // Box2D world (graphics)
    world = new World(new Vector2(0, -10), true);
    b2dr = new Box2DDebugRenderer();

    // New Jack
    player = new Jack(world);


    BodyDef bdef = new BodyDef();
    PolygonShape shape = new PolygonShape();
    FixtureDef fdef = new FixtureDef();
    Body body;


    // The ground as an object is defined
    for(MapObject object: map.getLayers().get(2).getObjects().getByType(RectangleMapObject.class)){
        Rectangle rect = ((RectangleMapObject) object).getRectangle();

        bdef.type = BodyDef.BodyType.StaticBody;
        bdef.position.set((rect.getX() + rect.getWidth()/2)/MainActivity.PPM, (rect.getY() + rect.getHeight()/2) /MainActivity.PPM);

        body = world.createBody(bdef);

        shape.setAsBox(rect.getWidth()/2, rect.getHeight()/2);
        fdef.shape = shape;
        body.createFixture(fdef);
    }
    public void update(float dt){
    handleInput(dt);

    world.step(1 / 60f, 6, 2);

    //gamecam.position.x = player.b2body.getPosition().x;

    gamecam.update();
    renderer.setView(gamecam);

}

@Override
public void render(float delta) {
    update(delta);

    // Clear the screen
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // render the map
    renderer.render();

    // render the box2d
    b2dr.render(world, gamecam.combined);



    game.batch.setProjectionMatrix(hud.stage.getCamera().combined);
    hud.stage.draw();


}

@Override
public void resize(int width, int height) {
        gamecam.viewportWidth = width;
        gamecam.viewportHeight = height;
}
HUD和主活动

 public HUD(SpriteBatch sb){
        worldTimer = 300;
        timeCount = 0;
        score = 0;

        viewport = new FitViewport(MainActivity.V_WIDTH, MainActivity.V_HEIGHT, new OrthographicCamera());
        stage = new Stage(viewport, sb);

        Table table = new Table();
        table.top();
        table.setFillParent(true);

        countdownlabel = new Label(String.format("%03d", worldTimer), new Label.LabelStyle(new BitmapFont(), Color.RED));
        scoreLabel = new Label(String.format("%06d", score), new Label.LabelStyle(new BitmapFont(), Color.RED));
        timeLabel = new Label("TIME", new Label.LabelStyle(new BitmapFont(), Color.RED));
        levelLabel = new Label("level 1", new Label.LabelStyle(new BitmapFont(), Color.RED));

        table.add(timeLabel).expandX().padTop(10);
        table.add(levelLabel).expandX().padTop(10);
        table.row();
        table.add(scoreLabel).expandX().padTop(10);

        stage.addActor(table);
    }

public class MainActivity extends Game {
public SpriteBatch batch;

    public static final int V_WIDTH = 720;
    public static final int V_HEIGHT = 480;
    public static final float PPM = 1;

    public static final String TITLE = "Jack the Pirate";

    @Override
    public void create () {
        batch = new SpriteBatch();
        setScreen(new PlayScreen(this));
    }

    @Override
    public void render () {
        super.render();

    }
}
我再也不知道该去哪里看了,我无数次地浏览了基本知识:(我的tmx tilemap是14个瓷砖宽,70个瓷砖高。瓷砖本身是16x16。我的测试设备是三星Galaxy S3,我想在纵向模式下使用它


有什么想法可以看吗?提前感谢您的帮助!

那么,相机当前发生了什么事情?相机在playscreen中初始化,并使用视口的参数除以2,因此它将显示全屏!问题是什么?它渲染了错误的对象吗?它甚至渲染了什么东西吗?您实际在哪里y渲染贴图?在
main活动中#render
实际上只调用
super.render()
,所以我想这里缺少了代码中最重要的部分。我可以看出我遗漏了一些代码,很抱歉!它以小比例渲染世界,周围有黑色条。我现在将编辑代码,以便我的渲染功能可见!