Multi touch ui issue

Anything libgdx related goes here!

Multi touch ui issue

Postby devhang » Sat Jun 16, 2012 4:17 am

Hello, I started my development with libgdx recently, the target platform is android
I have made a test screen an create a stage and put 2 Slider component (eg. slider1, silder2) into it.

TestScreen
Code: Select all
public class TestScreen extends BasicScreen implements ClickListener, Slider.ValueChangedListener {
   protected TextButton btnBack;
   
   protected Slider slider1;   
   protected Slider slider2;

   public TestScreen (Game core) {
      super(core);
      
      btnBack = new TextButton("Back", Assets.tbsCommonLarge, "btnBack");
      btnBack.x = 30;
      btnBack.y = 400;
      btnBack.setClickListener(this);

      slider1 = new Slider(0, 10, 0.1f, Assets.slsCommon, "slider1");
      slider1.width = 200;
      slider1.x = 150;
      slider1.y = 250;
      slider1.setValueChangedListener(this);
      
      slider2 = new Slider(0, 10, 0.1f, Assets.slsCommon, "slider2");
      slider2.width = 200;
      slider2.x = 150;
      slider2.y = 150;
      slider2.setValueChangedListener(this);
      
      stage.addActor(btnBack);
      
      stage.addActor(slider1);
      stage.addActor(slider2);
      
      Gdx.input.setInputProcessor(stage);
      
      System.gc();
   }

   @Override
   public void click(Actor actor, float x, float y) {
      // TODO Auto-generated method stub
      if (actor == btnBack) {
         core.setScreen(new MainScreen(core));
      }
   }

   @Override
   public void changed(Slider slider, float value) {
      if (slider == slider1) {
         if (!slider.isDragging()) {
            //do sth
         }
      }
      else if (slider == slider2) {
         if (!slider.isDragging()) {
            //do sth
         }
      }
   }
}

BasicScreen
Code: Select all
public class BasicScreen implements Screen {
   protected Game core;
   
   protected SpriteBatch batch;
   
   protected Stage stage;
   
   protected TextureRegion txrBackground;
   protected Image imgBackground;
   
   public BasicScreen(Game core) {
      this.core = core;
      
      batch = new SpriteBatch();
      
      stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, batch);
      
      txrBackground = new TextureRegion(Assets.texBackground, 0, 0, (int)stage.width(), (int)stage.height());
      imgBackground = new Image(txrBackground);
      imgBackground.setFillParent(true);
   
      stage.addActor(imgBackground);
   }
   
   @Override
   public void render(float delta) {
      // TODO Auto-generated method stub
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      
      stage.act(Gdx.graphics.getDeltaTime());
      stage.draw();
   }
   // ... other override method
}

Once I drag the slider1 (with finger1), but when I use another finger try to drag the slider2 (finger2), the 2 sliders are not act as what I expect, finger2 will dragging the slider1 but not slider2, that's mean I can't act with 2 or more UI component in same stage?
I am sure that my platform can support multi-touch, my development is stuck on this issue, hope someone can provide some advise to me, thank you very much.
devhang
 
Posts: 2
Joined: Sat Jun 16, 2012 3:54 am

Re: Multi touch ui issue

Postby mzechner » Sat Jun 16, 2012 9:28 am

Just like the Android native UI widgets, the libgdx UI widgets only support single touch i'm afraid.
mzechner
Site Admin
 
Posts: 4715
Joined: Sat Jul 10, 2010 3:50 pm

Re: Multi touch ui issue

Postby devhang » Sun Jun 17, 2012 4:54 pm

I see, I may try to dispatch the stage event for individual ui elements manually, thanks anyway. :)
devhang
 
Posts: 2
Joined: Sat Jun 16, 2012 3:54 am


Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 5 guests