Rey's Transparent Texture Method - UQdeco2800/2022-studio-2 GitHub Wiki

What is RTTM?

RTTM AKA Rey's Transparent Texture Method, AKA Placeholder Method, is a dedicated method used to deal with all the button clicks in libGdx game engine. It is widely used through out GameAreaDisplay method for triggering event on a pre-designed button asset. The purpose of this method is to use a brute-force strategy to place event listerners to a place where event listener is not allowed. Specifically, allow specific areas of an image to be interactive since Image.java does not support listerners to be placed.

Now many of you may wonder, why would I need RTTM, isnt RTTM just Texture.java? The benefit of using RTTM are as follows:

  • Texture is annoying, when it comes to positioning and resizing (works weirdly).
  • Simple and efficient.
  • Reduce workload for the design side. (No need to design separate widgets for buttons)
  • Easy to understand and safe to use.

Procedure of RTTM:

  1. Locate the transparent texture: images/crafting_assets_sprint2/transparent-texture-buttonClick.png
  2. Define a Image.java, use any image will be fine. (Preferably similar size with the size of the area you want to trigger event to take place)
  3. Define an actual Texture.java for later use.
  4. Since image is easier to manipulate, adjust the image until it allign with your desired area.
  5. Once the image is alligned, simply just swap the image with the pre-defined transparent texture in step one. (Don't forget to change the Image.java class to Texture.java class as well)

Use case

        buttonTexture = new Texture(Gdx.files.internal
                ("images/crafting_assets_sprint2/transparent-texture-buttonClick.png"));
        buttonTextureRegion = new TextureRegion(buttonTexture);
        buttonDrawable = new TextureRegionDrawable(buttonTextureRegion);
        ImageButton controls = new ImageButton(buttonDrawable);
        controls.setSize(386, 122.4f);
        controls.setPosition(pauseMenu.getX() + 762f, pauseMenu.getY() + 382);
        controls.addListener(
                new ChangeListener() {
                    @Override
                    public void changed(ChangeEvent changeEvent, Actor actor) {
                        logger.info("Key binding button things");
                        openPauseComponent.openKeyBindings();
                    }
                });
        pausingGroup.addActor(controls);

Who to talk to?

Rey (@Rey_cyz#1464 on discord, @Rey-666 on github)