1

So im new with libGDX and im making a game where if you press the image it rotates, witch means it changes the images for another. But i dont know who to do it, and i would like some help.

@Override
public void create () {

    spriteBatch = new SpriteBatch();
    font = new BitmapFont(true);
    camera = new OrthographicCamera();

    texture = new Texture(Gdx.files.internal("cable_side.png"));
    textureRegion = new TextureRegion(texture);
    textureRegion.flip(false, true);

    texture2 = new Texture(Gdx.files.internal("cable_l_1.png"));
    textureRegion2 = new TextureRegion(texture2);
    textureRegion2.flip(false, true);

    camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());


}

@Override
public void render () {


    Gdx.gl.glClearColor(0.4f, 0.4f, 0.4f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();
    spriteBatch.setProjectionMatrix(camera.combined);

    spriteBatch.begin();
    //font.draw(spriteBatch, "Hacking Time", 0, 0);
    spriteBatch.draw(textureRegion2, 0, 0);
    spriteBatch.draw(textureRegion, 32, 0);
    spriteBatch.draw(textureRegion, 64, 0);
    spriteBatch.draw(textureRegion, 96, 0);
    spriteBatch.draw(textureRegion, 128, 0);
    spriteBatch.draw(textureRegion, 160, 0);
    spriteBatch.draw(textureRegion, 192, 0);
    spriteBatch.draw(textureRegion, 224, 0);
    spriteBatch.end();
    }

Here's what i have, the second textureRegion on the horizontal and i want to put it on the vertical, removing the previous one. Please help!

gafflx
  • 27
  • 5

1 Answers1

1

There are lots of ways to do what you want so i'd like to advise you to try and read some of the documentation available at Libgdx also Games From Scratch have a couple of good tutorials.

But this isn't what you asked so... One of the most simple ways to accomplish what you want is using Stage and Actors.

Steps to do it:

  1. Create a Scene;
  2. Associate the Gdx input processor with the stage;
  3. Create a Skin to store your UI resources;
  4. Create ImageButtonStyle with the up parameter with your original image and cheked with the image you want to swap with;
  5. Create ImageButtons with the previous ImageButtonStyle.

Here in another Stackoverflow Topic user DannyBit provides a code sniplet that does something similiar with a textbutton.

Community
  • 1
  • 1
João Costa
  • 412
  • 4
  • 15