1
\$\begingroup\$

I am writing a Tower Defense for Android. Right now my LevelScreen contains a Background-Actor which is pan-able and some zones to buy Towers - after buying them you can upgrade them further. When you click a Zone or a Tower, a small overlay on the bottom appears (another actor) - click it to buy. My main Problem was that the overlay stayed where you clicked and didn't move when you pan the Screen. I solved this by changing the overlay's draw method to

batch.setProjectionMatrix(game.batch.getProjectionMatrix());
batch.draw(texture,actorX,actorY);
batch.setProjectionMatrix(levelScreen.stage.getCamera().combined);

I set it backwards for further Actors who should stay where they are - Towers for example - but I kinda don't know what I am really doing.

I am now only able to fire the touchDown Event on these actors when I pan to the bottom left of the Screen and click where the Actor's Icon is.

I tried a few things:

-Adding another Stage as a HUD(I couldn't Access the lower stage anymore or the other way around)

-Moving the actor.x and actor.y along (I was unable to even find where the actor went)

-Adding another camera (led to nothing)

-Updating the actors Position using

stage.getCamera().unproject(myPoint) 

(same as when I tried to move the actor)

So, which is a good way to implement what I look for? Basically, TL;DR: I am looking for a way of letting some Actors stay relative to Screen while moving some Actors with the world while panning around.

I am pretty sure there a similar questions but None of them really helped me and I have restricted Internet-Access (for example I can't Access badlogicgames.com).

\$\endgroup\$
1
\$\begingroup\$

Adding another Stage as a HUD(I couldn't Access the lower stage anymore or the other way around)

It's the solution i'm using, and for me it's working fine. Assuming that by "couldn't access" you meant you couldn't handle input, you have to know there is a solution for this : InputMultiplexer.

It allows you to handle event for multiples scenes and/or input processors.

Code Example :

Stage scene;
Stage hud;
...
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(hud);
multiplexer.addProcessor(scene);
Gdx.input.setInputProcessor(multiplexer);
\$\endgroup\$
0
\$\begingroup\$

Yes, you need two stages, one of the UI and one for the game. You can find a code sample here on LibGDX.info:

https://libgdx.info/multiplexing/

Hope it helps!

\$\endgroup\$

Your Answer

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

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