Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to make 2 separate classes, 1 a VirtualJoystick class and 1 a VirtualButton class. I want to implement a GestureListener class in each, it just seems like good code to do so, but when I go to my main program, how do I add both GestureListener classes?

Here's some pseudocode that I'm thinking of:

VirtualJoystick vjs = new VirtualJoystick(x, y, width, height, bgImage, fgImage);
VirtualButton vb    = new VirtualButton(x,  y,  width, height, upImage, dnImage);

GestureDetector joyGestureDetector = new GestureDetector( vjs.getDetector() );
GestureDetector btnGestureDetector = new GestureDetector(  vb.getDetector() );

// Here's what I don't know how to do
GestureDetector combinedGestureDetector = ?

Gdx.input.setInputProcessor(combinedGestureDetector);

but as you can see, I'm stuck on how to combine the two, if there's a better way let me know, I'm just trying to get my code to "think through well" and be atomically contained in classes.

share|improve this question
    
I have a feeling I'm going about this all wrong, I know now that I can use Gdx.input.isTouched(); but I'm not sure how to do multiple buttons and a joystick just yet. –  mathacka Apr 22 '13 at 23:00
add comment

1 Answer

up vote 1 down vote accepted

The quick and dirty way to fix this is to use InputMultiplexer. This allows you to pass those gesture events to both detectors.

VirtualJoystick vjs = new VirtualJoystick(x, y, width, height, bgImage, fgImage);
VirtualButton vb    = new VirtualButton(x,  y,  width, height, upImage, dnImage);

GestureDetector joyGestureDetector = new GestureDetector( vjs.getDetector() );
GestureDetector btnGestureDetector = new GestureDetector(  vb.getDetector() );
//Note: you need return false in your event handlers like touchDown(...), 
//so that the event gets passed to both detectors you added to the multiplexer.
InputMultiplexer multiplexer= new InputMultiplexer(joyGestureDetector,btnGestureDetector);

Gdx.input.setInputProcessor(multiplexer);
share|improve this answer
    
Thank you very much! –  mathacka Apr 24 '13 at 1:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.