0
\$\begingroup\$

Well, I'm a beginner in libGDX and till now I used image-buttons to draw something which can be clicked for example. However image-buttons are really hard to draw, in fact you have to use it with a stage and a viewport, instead textures are easier. I noticed that textures are ALWAYS at the same position in our game if we change device and this is very useful, instead image buttons can give you lots of problems because you have a stage and a viewport, above all if there are textures too. So I decided to bypass the image buttons and I did something like this:

public class MyView extends Texture implements InputProcessor
{

   public Tasto(String string)
   {
       super(string);
       Gdx.input.setInputProcessor(this);
   }

   //all InputProcessor methods
}

In this way I have a texture which is clickable and I'll continue in this way if there aren't problems. But so image buttons are useless. So, what are image buttons used for? Why using them if I can do in this way?

\$\endgroup\$
  • \$\begingroup\$ I believe you've just misunderstood viewports and stages, Curio ;) Your approach is equivalent to using a ScreenViewport. Try using only ScreenViewport and you will see that they are exactly the same since both textures and ScreenViewport uses your screen resolution to size and draw things. \$\endgroup\$ – Charanor Jun 25 '17 at 18:01
  • \$\begingroup\$ Or StretchViepwort would probably also work. It's exactly the same except that it uses a virtual screen size. \$\endgroup\$ – Charanor Jun 25 '17 at 18:09
  • \$\begingroup\$ @Charanor but I saw that ScreenViewport has an issue: if the screen is bigger, you can see more map. In this way there isn't this problem, I mean: on a tv and on a mobile there are always for example 30 blocks \$\endgroup\$ – Curio Jun 25 '17 at 18:23
  • \$\begingroup\$ That's what a StretchViewport is there for. It supports a virtual screen size as I said (as in always 30x30 blocks or whatever size you pick). \$\endgroup\$ – Charanor Jun 25 '17 at 18:31
  • \$\begingroup\$ @Charanor Ok, what is the best between these two methods? And how do I use this StrechViewport? \$\endgroup\$ – Curio Jun 25 '17 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.