gpt4 book ai didi

java - libGDX - Tiled 渲染问题

转载 作者:太空宇宙 更新时间:2023-11-04 14:35:04 25 4
gpt4 key购买 nike

由于某种原因,当我逃跑时,屏幕边缘的我身后的方 block 消失了。很难拍到他们这样做的镜头,因为每一帧都不同,但这就是它的样子:

enter image description here

如果有人可以告诉我为什么这样做那就太棒了:)

public void show() {
map = new TmxMapLoader().load("assets/maps/map.tmx");

renderer = new OrthogonalTiledMapRenderer(map);
sr = new ShapeRenderer();
sr.setColor(Color.CYAN);
Gdx.gl.glLineWidth(3);

camera = new OrthographicCamera();
}

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

camera.position.set(player.getX() + player.getWidth() / 2, player.getY() + player.getHeight() / 2, 0);
camera.update();

renderer.setView(camera);

renderer.render(background);

renderer.getSpriteBatch().begin();
player.draw(renderer.getSpriteBatch());
renderer.getSpriteBatch().end();

renderer.render(foreground);

// render objects
sr.setProjectionMatrix(camera.combined);
for(MapObject object : map.getLayers().get("objects").getObjects())
if(object instanceof RectangleMapObject) {
RectangleMapObject rectObject = (RectangleMapObject) object;
Rectangle rect = rectObject.getRectangle();
if(rectObject.getProperties().containsKey("gid")) { // if it contains the gid key, it's an image object from Tiled
int gid = rectObject.getProperties().get("gid", Integer.class);
TiledMapTile tile = map.getTileSets().getTile(gid);
renderer.getSpriteBatch().begin();
renderer.getSpriteBatch().draw(tile.getTextureRegion(), rect.x, rect.y);
renderer.getSpriteBatch().end();
} else { // otherwise, it's a normal RectangleMapObject
sr.begin(ShapeType.Filled);
sr.rect(rect.x, rect.y, rect.width, rect.height);
sr.end();
}
} else if(object instanceof CircleMapObject) {
Circle circle = ((CircleMapObject) object).getCircle();
sr.begin(ShapeType.Filled);
sr.circle(circle.x, circle.y, circle.radius);
sr.end();
} else if(object instanceof EllipseMapObject) {
Ellipse ellipse = ((EllipseMapObject) object).getEllipse();
sr.begin(ShapeType.Filled);
sr.ellipse(ellipse.x, ellipse.y, ellipse.width, ellipse.height);
sr.end();
} else if(object instanceof PolylineMapObject) {
Polyline line = ((PolylineMapObject) object).getPolyline();
sr.begin(ShapeType.Line);
sr.polyline(line.getTransformedVertices());
sr.end();
} else if(object instanceof PolygonMapObject) {
Polygon poly = ((PolygonMapObject) object).getPolygon();
sr.begin(ShapeType.Line);
sr.polygon(poly.getTransformedVertices());
sr.end();
}
}

最佳答案

我正在使用OrthogonalTiledMapRenderer

它现在正在工作,并且图 block (更大的图 block )不会消失:

    float x = orthographicCamera.position.x - orthographicCamera.viewportWidth * orthographicCamera.zoom;
float y = orthographicCamera.position.y - orthographicCamera.viewportHeight * orthographicCamera.zoom;

float width = orthographicCamera.viewportWidth * orthographicCamera.zoom * 2;
float height = orthographicCamera.viewportHeight * orthographicCamera.zoom * 2;

orthogonalTiledMapRenderer.setView(orthographicCamera.combined, x, y, width, height);

关于java - libGDX - Tiled 渲染问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25693571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com