2

I am implementing one game where I want to repeat one image along x direction.I searched for it on the web but could not get the correct approach. There is a grass image and I want to repeat it all along the ground in x direction.

Kindly provide some suggestions and possible ways to do it.

I am using following code to draw Image inside render method.

  spriteBatch.draw(grass, 0, 0);
bemeyer
  • 6,154
  • 4
  • 36
  • 86
Jigar Pandya
  • 2,129
  • 2
  • 17
  • 27
  • 1
    Check out this might help you. http://javamilf.blogspot.in/2013/07/libgdx-repeating-background-image.html – GrIsHu Mar 10 '14 at 13:07

1 Answers1

2

Let's try a simple for loop

for(int i = 0; i <= Gdx.graphics.getWidth(); i += grass.getWidth() {
    spriteBatch.draw(grass, i, 0);
}

I assume grassis an instance of Sprite. If that doesn't work, don't hesitate to comment back.

Ferdz
  • 1,182
  • 1
  • 13
  • 31