public void create() { //код stage = new Stage(); stage.addActor(tank); // оба танка наследуются от 1 класса stage.addActor(tank2); Gdx.input.setInputProcessor(stage); } 

render

 public void render() { //код stage.act(Gdx.graphics.getDeltaTime()); stage.draw(); //код } 

both actor are displayed, but only tank2 responds to pressing.

How to make it so that when you press 1 with a finger, both actor'a react simultaneously?

I tried InputMultiplexer, but they react to pressing with 2 fingers (each actor with 1 finger in turn).


in the description for the Stage class:

If you want to make a note of the event

If actor processed the event, returning true from the input method, then the input method of the Stage class will also return true, as a result the subsequent InputProcessors will not receive the event.

    1 answer 1

    You just need to add the same InputListener to both objects.

    If I understand correctly, then you need something like this:

     InputListener myListener = new InputListener() { @Override public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { // Двигаем объекты tank.move(); tank2.move(); return true; // Говорим, что нажатие было обработано } }; tank.addListener(myListener); tank2.addListener(myListener); 
    • Thanks, now they are working synchronously (the first tank repeats after tank2). And how to make everyone move independently of each other? That is, if they are on the left and right of the screen, and when pressed, for example, in the center, it is necessary that they both move to the center from their positions .. - Rusl Mag
    • @RuslMag change the function code - it can be any. This is essentially a completely different question - therainycat
    • Understood, thanks for helping with the question. I will try - Rusl Mag