Libgdx Background Textureregion Repeat
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.
Solution 3:
I have created an introduction to images including repeating texture here: https://libgdx.info/basic_image/
I hope it helps
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"