How to show disable state of UIButton?


#1

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?


#2

->disable (true);


#3

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


#4

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

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


#5

@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 ?


#6

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


#7

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


#8

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


#9

@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.


#10

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


#11

@dungmv wrote:

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


#12

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


#13

setBright(bool) is useful


#14

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


#15

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


#16

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.


#17

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 ?


#18

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