Question

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);
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top