Skip to content Skip to sidebar Skip to footer

Libgdx Background Textureregion Repeat

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

Solution 1:

I progressed in solving my problem. I use the setWrap method to repeat my texture :

publicclassBackgroundextendsAbstractGameObject {

   private TextureRegion regBackground;

   publicBackground(int width, int heigth) {
      init(width, heigth);
   }

   privatevoidinit(int width, int heigth) {
      dimension.set(width, heigth);
      regBackground = Assets.instance.levelDecoration.background;

      origin.x = -dimension.x/2;
      origin.y = -dimension.y/2;
   }

   publicvoidrender(SpriteBatch batch) {
      TextureRegionreg=null;
      reg = regBackground;

      Texturetest= reg.getTexture();
      test.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
      batch.draw(test, 
            position.x + origin.x, position.y + origin.y, 
            test.getWidth(), test.getHeight(), 
            reg.getRegionX(), reg.getRegionY(), 
            reg.getRegionWidth(), reg.getRegionHeight()       
            );

   }
}

Now, I obtain this, but I just want to repeat my background image (wood square).

http://s24.postimg.org/c1m92ffwx/Capture_du_2013_11_12_15_49_03.jpg

The problem is that the getTexture() recover the all image and not only my background. How can I fix this?

Solution 2:

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

Solution 3:

I have created an introduction to images including repeating texture here: https://libgdx.info/basic_image/

I hope it helps

This creates an image along this line: enter image description here

Solution 4:

a simpler approach will be

 batch.draw(imageReference,startX,startY,widthOfScreen,heightOfScreen);

batch.draw() is an overloaded method so use only those parameter u need the syntax is just a pseudo code

MOst importantlu This may give image stretching(depending on image).

Post a Comment for "Libgdx Background Textureregion Repeat"