How to show disable state of UIButton?

I made some ui with CocoStudio 1.1.0.0.
and load it into Scene.
when i set uiButtonInstance->setEnable(false),
it disappear on screen, instead of showing disable state.

I found comment of UIWidget.setEnabled on cpp source says…

“true if the widget is enabled, widget may be touched and visible, false if the widget is disabled, widget cannot be touched and hidden.”

if so, when disable state is shown?

1 Like

->disable (true);

disable (bool containChildren=false)

For more detail:
http://www.cocos2d-x.org/reference/native-cpp/V2.2/d7/d2d/classcocos2d_1_1extension_1_1_u_i_button.html

Where is the method “->disable()” ?
I have the same problem with @volzh.

Is there any property with the meaning of “DISABLE” in common scence ?

1 Like

@jamjamcat

Where is the method “->disable()” ?
I have the same problem with @volzh.

Is there any property with the meaning of “DISABLE” in common scence ?

1 Like

I can not find a method to disable of uibutton, if i call method setEnabled for uibutton then it is invisible and I can not see it on screen.
so, how can i set disable state for uibutton?
i use cocos2dx-2.2.3 and coco studio 1.2.0.1

@dungmv
Is it setBright() this makes no sense but may work for you…

1 Like

@dungmv
@zjh1943
In my UI for dynamic buttons I find ->removeFromParent() works well!

@dungmv
You have good English! but this:-
I can not found find a method to disable of uibutton, if i call method setEnabled for uibutton then it is invisible and I can not see it in on screen.
so, how can iI set disable state for uibutton?

Your English is much,much better than my grasp of your language.
I only want to help you improve.

Thank you, I am learning English, I will try harder

@dungmv wrote:

thank you, I am learning English :slight_smile: I will try beater harder

@dungmv
Does it help you if I do this ^^ ?
Or should I quit?

setBright(bool) is useful

3 Likes

why setEnable false is not working ? and setBright is working? is it intended?

Thanks for the setBright solution although this makes no sense at all!

There’s no disable(), it’s setEnabled(boolean).setBright(boolean)just changes the visual sprite basically.setEnabledcalledsetBright` anyway, so you don’t need to double up on that’.

I’ve got a related question, is it possible to disable a button but still have it swallow touches, as in if you disable a button, have the touch not touch the thing thats behind it? button->setSwallowTouches(true) doesn’t seem to do it, neither does button->setTouchEnabled(true) nor did button->setPropagateTouchEvents(false).

Looking at the source, Widget::onTouchBegan returns false before checking anything other than isVisible or isEnabled, so maybe I can’t without subclassing.

I have used setBright(false) when showing the disabled state of the Button. Basically button activates power-up and I need to add logic such that button remains disabled while power-up is on cooldown.
But there is a weird issue. When setBright(false) is called for first time, the button disappears from HUD . After cooldown gets over, button becomes visible again. Now if I activate the power-up, then setBright(false) works as intended and button becomes greyed and not invisible.

How do I fix this ?

I don’t really understand your problem. Do you have a selected texture?

I do, do i follow this topic? I’m in the same situation, though i see this is quite old

I have a set texture but the button keeps the same image

solved. I forgot to add .png.

Yes it very well seems naive but we all make mistakes

how are you creating a button?