libgdx背景TextureRegion重复

libgdx背景TextureRegion重复

本文介绍了libgdx背景TextureRegion重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在libdgx研究与开发新也在游戏的研究与开发。我读给Andreas Oehlke书学习Libgdx游戏开发,我试图并行开发自己的比赛。
我有一个问题,当我尝试添加背景。在这本书中,他用一种颜色,所以这是非常简单的。但是,我想从一个纹理图集添加图像。该图像是小恢复所有屏幕上,所以我想再说一遍。我不能使用regBackground.setWrap(TextureWrap.Repeat,TextureWrap.Repeat),因为regBackground不是质感。我怎么能妥善解决我的问题?

 公共类背景扩展AbstractGameObject {   私人TextureRegion regBackground;   公共背景(){
      在里面();
   }   私人无效的init(){
      dimension.set(1F,1F);
      regBackground = Assets.instance.levelDecoration.background;
   }   公共无效渲染(SpriteBatch批){
      TextureRegion章= NULL;
      章= regBackground;
      batch.draw(reg.getTexture(),
            position.x,position.y,
            origin.x,origin.y,
            dimension.x,dimension.y,
            scale.x,scale.y,
            回转,
            reg.getRegionX(),reg.getRegionY(),
            reg.getRegionWidth(),reg.getRegionHeight(),
            假的,假的);
   }
}

在我的资产类中,我有这样的code找到该地区的纹理图集:

 公共类AssetLevelDecoration {
         公众最终AtlasRegion背景;         公共AssetLevelDecoration(TextureAtlas阿特拉斯){
             背景= atlas.findRegion(背景);
      }
   }


解决方案

我只想补充注释,但我没有代表。

要解决整机的质感,而不是只木方的重复的问题,你有两个选择。一)textureregion分离到单独的质感。 B)的环在重复拉伸,这应该是可以忽略不计在性能方面

I'm new in libdgx developement and also in game developement. I am reading the book "Learning Libgdx Game Development" from Andreas Oehlke and I am trying to develop my own game in parallel.I have a problem when I try to add the background. In the book, he uses a color, so it's very simple. But I want to add an image from a texture atlas. The image is to small to recover all the screen, so I want to repeat it. I can't use regBackground.setWrap(TextureWrap.Repeat, TextureWrap.Repeat) because regBackground is not a texture. How i can resolve my problem properly?

   public class Background extends AbstractGameObject {

   private TextureRegion regBackground;

   public Background () {
      init();
   }

   private void init () {
      dimension.set(1f, 1f);
      regBackground = Assets.instance.levelDecoration.background;
   }

   public void render (SpriteBatch batch) {
      TextureRegion reg = null;
      reg = regBackground;
      batch.draw(reg.getTexture(),
            position.x, position.y,
            origin.x, origin.y,
            dimension.x, dimension.y,
            scale.x, scale.y,
            rotation,
            reg.getRegionX(), reg.getRegionY(),
            reg.getRegionWidth(), reg.getRegionHeight(),
            false, false);
   }
}

In my Assets class, I have this code to find the region in the texture atlas :

     public class AssetLevelDecoration {
         public final AtlasRegion background;

         public AssetLevelDecoration (TextureAtlas atlas) {
             background = atlas.findRegion("background");
      }
   }
解决方案

I would just add a comment but I don't have the rep.

To solve the issue of the repeating of the whole texture instead of only the wooden square you have 2 choices. A) separate the textureregion onto a separate texture. B) loop over the to repeat the draw, which should be negligible in terms of performance.

http://badlogicgames.com/forum/viewtopic.php?f=11&t=8883

这篇关于libgdx背景TextureRegion重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:02