An example would be a popup for some game options with an alpha of less than 1 (and more than 0 of course). You add a button as a child of the popup. The button inherits the alpha from the popup and his appearance is not good because of this. For example if the button colour is white then it appears with a colour mix from white to the popup colour (due to the button alpha inherited).
Of course the button could be a child of the main stage (background with alpha=1) instead of the popup, but therefore you have to manage the functionality of the button in the main class code and not in the popup class. Anyway I know it's possible to manage the button as a child of the main stage, but it's not logical and it's not desirable to set the position related to the background instead of the popup.
aha, I see. Well you could have a Popup class which inherits from Sprite And then add the layer to dim the background and then add all the buttons on the same Popup sprite
As layer is the first child it will be beneath all of the popup content and you can adjust its transparency as you want
But you can also use shape to dim the background with fill style, which actually is not inherited to children sprites
@ar2rawseen I want the popup to have the transparency. I don't want to dim the background. I mean that if you set an alpha for the popup all the content will be also with the transparency. That it's just I want to avoid because the appearance is not good especially with the white color.
Anyway one solution is to add the buttons to the background (after the popup) and having to set the background related coordinates.
@SimplesApps I understand that, dimming was only the example Basically have a Popup as a Sprite, and divide contents in two layers, the one with alpha and the one without alpha
I would do exactly the same : Create an instance (myPopup) of my popup class (inherits from Sprite) - use myPopup (Sprite) as a container -- add a (Sprite) myBackground as a child of myPopup (play with alpha) -- add a (Sprite) myButton as a child of myPopup
Comments
So please elaborate more on your set up and what you want to achieve
Of course the button could be a child of the main stage (background with alpha=1) instead of the popup, but therefore you have to manage the functionality of the button in the main class code and not in the popup class. Anyway I know it's possible to manage the button as a child of the main stage, but it's not logical and it's not desirable to set the position related to the background instead of the popup.
https://play.google.com/store/apps/developer?id=SimplesApps
http://www.amazon.com/gp/mas/dl/android?p=com.simplesapps.actionbasket
https://itunes.apple.com/artist/david-rodriguez/id763996989
Well you could have a Popup class which inherits from Sprite
And then add the layer to dim the background
and then add all the buttons on the same Popup sprite
As layer is the first child it will be beneath all of the popup content and you can adjust its transparency as you want
But you can also use shape to dim the background with fill style, which actually is not inherited to children sprites
Example:
https://github.com/ar2rsawseen/GameTemplate/blob/master/classes/Popup.lua
Hope it makes sense
Anyway one solution is to add the buttons to the background (after the popup) and having to set the background related coordinates.
Fyi I'm using the bhPopup class from Bowerhaus.
https://play.google.com/store/apps/developer?id=SimplesApps
http://www.amazon.com/gp/mas/dl/android?p=com.simplesapps.actionbasket
https://itunes.apple.com/artist/david-rodriguez/id763996989
Basically have a Popup as a Sprite, and divide contents in two layers, the one with alpha and the one without alpha
Is there anything that wouldn't work with the solution @ar2rsawseen has provided?
I would do exactly the same :
Create an instance (myPopup) of my popup class (inherits from Sprite)
- use myPopup (Sprite) as a container
-- add a (Sprite) myBackground as a child of myPopup (play with alpha)
-- add a (Sprite) myButton as a child of myPopup