OrthogonalTiledMa prenderer和正常Spritebatch呈现一个白盒子? [英] OrthogonalTiledMapRenderer and normal Spritebatch renders a white box?

查看:276
本文介绍了OrthogonalTiledMa prenderer和正常Spritebatch呈现一个白盒子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Libgdx渲染tilemap的为我的游戏背景。我可能使以后的一些不同的层次。
如果没有tilemap的渲染和一个单一的背景图片能够正常工作!
奇怪的事情发生时,我使用TiledRender只是看看吧:

I am using Libgdx to render a TileMap as a background of my game. I might render some different layers later on. Without the tilemap render and a single background picture it works correctly! Something strange happens when i use the TiledRender just take a look at it:

这两个白色区域通常触摸板和字符。

The two white areas are normally a touchpad and a character.

触摸板和字符都呈现有:

The touchpad and the character are rendered with:

@Override
   public void draw(SpriteBatch batch, float parentAlpha) {
      sprite.draw(batch);
   }

我的地图,其中i渲染我tilemap的是这样的:

My Map where i render my TileMap looks like this:

public class Map extends Actor {
   private TiledMap map;
   private OrthogonalTiledMapRenderer render;
   public int[][] mapArray = new int[Config.X_SIZE][Config.Y_SIZE];

   public Map(TiledMap map){
      this.map  = map;
      this.render = new OrthogonalTiledMapRenderer(map,(((float)Config.VIRTUAL_VIEW_HEIGHT/Config.Y_SIZE)/(float)Config.TILE_SIZE));
      this.toBack();
   }

   @Override
   public void draw(SpriteBatch batch, float parentAlpha) {
      this.render.setView((OrthographicCamera) this.getStage().getCamera());
      render.render();
   }
}

任何sugestions来解决这个问题SpriteBatch?

any sugestions to fix the SpriteBatch problems?

推荐答案

许多Libgdx的渲染器辅助对象认为他们自己的OpenGL的运行状态,所以输出会很困惑,如果你有他们两个在修改OPENGL同时。在你的情况 OrthogonalTiledMa prenderer 都有自己的 SpriteBatch ,所以你有两个 SpriteBatch (默默)各自为战。

Many of the Libgdx render helper objects assume they "own" the state in the OpenGL runtime, so the output gets confused if you have two of them making changes to OpenGL at the same time. In your case the OrthogonalTiledMapRenderer has its own SpriteBatch, so you have two SpriteBatch (silently) fighting each other.

试着改变你的 Map.render()渲染方法地图之前结束正在进行的SpriteBatch(再之后重新启动它):

Try changing your Map.render() method to end the in-progress SpriteBatch before rendering the map (and then restart it afterwards):

@Override
public void draw(SpriteBatch batch, float parentAlpha) {
  batch.end();
  this.render.setView((OrthographicCamera) this.getStage().getCamera());
  render.render();
  batch.begin();
}

如果帮助,您可以看看设置你的瓦片地图共享同一个 SpriteBatch 为您的code的(其余的,因为这些都是有点重物)。这应该是更高效,更应该删除需要结束/启动 SpriteBatch

If that helps, you might look at setting up your tile map to "share" the same SpriteBatch as the rest of your code (as these are somewhat heavy objects). That should be more efficient and should remove the need to end/start the SpriteBatch.

这篇关于OrthogonalTiledMa prenderer和正常Spritebatch呈现一个白盒子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆