Draw parent in front of child

Anything libgdx related goes here!

Draw parent in front of child

Postby xpdt » Sun Jan 12, 2020 6:25 am

I have a Window that is added by addActore to another Window. Now is it possible to show parent in front of child?
xpdt
 
Posts: 88
Joined: Mon Jul 04, 2016 2:29 am

Re: Draw parent in front of child

Postby shatterblast » Mon Jan 13, 2020 5:43 am

xpdt wrote:I have a Window that is added by addActore to another Window. Now is it possible to show parent in front of child?

I suppose it depends on the order of things. I'm not sure how you're using an Actor to implement a Window, but you might consider Stack as an option. It's also possible to setVisible() and setTouchable() in certain situations with an Actor. That could also help if you find trouble changing your order of objects.
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Re: Draw parent in front of child

Postby xpdt » Mon Jan 13, 2020 11:42 am

I want to darken the entire screen when I display a window like the one below.
This may sound funny
https://ibb.co/W5vMKzX
xpdt
 
Posts: 88
Joined: Mon Jul 04, 2016 2:29 am

Re: Draw parent in front of child

Postby shatterblast » Mon Jan 13, 2020 4:41 pm

The easiest way would involve using multiple Stage objects and an InputMultiplexer. You can achieve what you want with either two or three Stage objects. To explain, you would want...

A) Your main game Stage. Feed this into your InputMultiplexer in the "firstLoad" if block. You may need to use a getter method to reference the variable from your main game class if you decide to split off your data into a separately individual class. Such would still feed into the render() method of your main class, and that would be why.
B) Second Stage with whatever translucency effects. Do NOT ever include this in your InputMultiplexer.
C) Third Stage with your Window. You can use the clear() method of InputMultiplexer and then add this third Stage to it. Everything else should refuse input while only the Window or whatever else of your third Stage does.

The Delta variable has the possibility of moving game logic forward. For instance, you might practice this with a ProgressBar. To start with, you can use an if block with a boolean variable in the render() method, like with the "firstLoad" if block above, to either shut off or enable the flow of game logic. You can make your own methods that accept the Delta float variable to make things easier to organize. You might think of it as a Pause feature.

You can do that with the below code.
Code: Select all
Gdx.graphics.getDeltaTime()


In the example of a ProgressBar, let the Delta variable do its own thing. Once it reaches a threshold, for instance the maximum value of your ProgressBar or higher, then you can consider resetting your ProgressBar contents back down to 0. You really need this technique to do a lot of fancy things with Scene2D. Regardless, you could use such to create a fading in and out effect with your second Stage that holds the darkened screen. The same applies to any Actor of course, including the near entirety of Scene2D itself.

1) https://libgdx.badlogicgames.com/ci/nig ... lexer.html
2) https://libgdx.badlogicgames.com/ci/nig ... eltaTime--
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm


Return to Libgdx

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest