Question

I am working on a Street Fighter Game. I need to have a character selection screen for the user. How can I do this character selection in Java libGDX? This is my image code. Can I do this using ImageClick event?

splashTexture1 = new Texture(Gdx.files.internal("assets/gui/Character1.PNG"));
splashTexture1.setFilter(TextureFilter.Linear, TextureFilter.Linear);
splashSprite1 = new Sprite(splashTexture1);     
splashSprite1.setX(100);
splashSprite1.setY(180);

No correct solution

OTHER TIPS

My suggestiong is using scene2d for menu or HUD stuff. Check this out : https://github.com/libgdx/libgdx/wiki/Scene2d

scene2d is a 2D scene graph for building applications and UIs using a hierarchy of actors:

  • buttons
  • labels
  • sliders
  • text buttons
  • scrollable views (lists)
  • tables
  • your custom widgets
  • group of actors

You can add ClickListener to an actor. (In your case the actor is a Button)

You can do it in two ways. I'd recommend using both.

Common stuff
You can list images of all characters in a screen. And let the user select any one using one of the following.

  1. Click event
    Each image will have a separate ClickListener (If you have problem regarding that, you should search 'How to add clicklisteners to libgdx actors).
    On clicking any image, the variable storing selected character (for the rest of the game) will be set with the image that has been clicked. And the screen is changed.
  2. Keyboard event
    One of the image will have focus drawn around it. The user can move focus around to other character images using arrow keys. When user presses enter, the character that currently has focus gets selected and the screen is changed.

Hope this helps.

I would recomend to use the Table-Layout from libgdx for it. Add an ImageButton to a Table and add an ClickListener to the ImageButton. Add the same Texture as up and down Texture and you are done. Maybe change it later so the user see that he has clicked a figure.

The Table gives you the ability to arrange those Buttons in the way you like and it's structured. Moreover it is easy to create a dynamic view, that does have new ImageButton for every new Texture you add to a folder for example. Just create a ScrollPane with a the Table of "figures" (which are the ImageButton with an listener) and you can add a bunch of it and let the user scroll down and up to check which he likes.

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