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(); //код } 

How to make each actor move independently of each other when you click on the screen? That is, if they are to the left and to the right of the screen, and when pressed, for example, to the center, it is necessary that they both move to the center from their positions.

With this code, of course only tank2 moves.

Stage works only with the first actor, which processed the event first. What methods need to be redefined so that the event is passed to the second actor? Or what logic to use?

PS A similar question, which was asked in the list below, was formulated a bit incorrectly, so in fact this is another question, but the answer was useful for me, and I hope for others.

    1 answer 1

    Moving the actors to a specific point on the screen can be done using

     Actions.moveTo( Gdx.graphic.getWidth() / 2.0, Gdx.graphic.getHeight() / 2.0, 2.0f /**seconds*//*, Interpolation.linear */ ); 

    And adding actions to actors using Containers

      Container<Actor> tankContainer = new Container<Actor>( tank ); tankContainer.addAction( Actions.sequence( Actions.moveTo( 0, Gdx.graphic.getHeight() / 2.0 ), Actions.moveTo( Gdx.graphic.getWidth() / 2.0, Gdx.graphic.getHeight() / 2.0, 2.0f /*seconds*//*, Interpolation.linear */ ) ); mStage.addActor( tankContainer ); Container<Actor> tankContainer_2 = new Container<Actor>( tank_2 ); tankContainer_2.addAction( Actions.sequence( Actions.moveTo( Gdx.graphic.getWidth(), Gdx.graphic.getHeight() / 2.0 ), Actions.moveTo( Gdx.graphic.getWidth() / 2.0, Gdx.graphic.getHeight() / 2.0, 2.0f /*seconds*//*, Interpolation.linear */ ) ); mStage.addActor( tankContainer_2 ); в render'е mStage.act( delta ); mStage.draw(); 

    And in the Tank class it is necessary to use for the position of the tank when drawing methods

     getX() и getY() 

    And if you want to turn the tanks, then

     tankContainer_2.addAction( Actions.rotateBy(...) ); 

    and when drawing Tank's class you can use

     getRotation() 

    And to catch a click anywhere on the screen, you can inherit from InputProcessor, and with Gdx.input.setInputProcessor it is better to use InputMultiplexer

     InputMultiplexer input = new InputMultiplexer(); input.add( mStage ); input.add( this ); Gdx.input.setInputProcessor( input ); 
    • Same. Most likely you need to deal with the method: @Override public Actor hit(float x, float y, boolean touchable) { return this; } @Override public Actor hit(float x, float y, boolean touchable) { return this; } - Rusl Mag