I have a texture that is part of a sprite sheet. I want draw the texture to cover a certain length, but I want it to repeat not stretch. However,when I use the following code

batch.draw(hillBottom, hill1.getX(), hill1.getY(), hill1.getWidth(), hill1.getHeight(), 0, 0, 1, hill1.getNumBlocks());

I receive an error indicating that the first argument must be a Texture not a Texture Region. I am new to game development, but I have read from multiple different guides that loading seperate textures in a game hinders performance which is why it should only be done if completely necessary. Is there anyway I can repeat the Texture Region?


I don't think this is possible in your case. A repeating texture at the hardware level needs to span the entire texture, at least on the axis it is repeating.

You can still repeat the sprite if you write your own routine. You would just call draw() multiple times.

If you decide to load your repeating sprite as a separate texture so you can render it in one draw call, you might also want to make the width a power of 2 (e.g. 32, 64, 128), because even devices supporting NPOT textures might not support them as repeating textures.

  • \$\begingroup\$ Thank you. I will just call the draw method multiple times I suppose. \$\endgroup\$ – Ayman Elmubark Jun 30 '15 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.