libGDX - Tiled的渲染问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了libGDX - Tiled的渲染问题相关的知识,希望对你有一定的参考价值。
出于某种原因,当我跑开时,屏幕边缘处的挡板消失了。很难得到他们这样做,因为每帧都不同,但这就是它的样子:
如果有人可以请告诉我为什么这样做会很棒:)
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
。
它现在正在工作,瓷砖(更大的瓷砖)不会消失:
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);
以上是关于libGDX - Tiled的渲染问题的主要内容,如果未能解决你的问题,请参考以下文章
开源java游戏框架libgdx专题-13-开发工具-地图的使用