CCControlButton responds to events even if its hidden (by its parent)

Hi,

I have a CCLayer inside which there is a CCControlButton, which calls a method when its clicked, but when i set that layer’s visibility to false, the function should not be called,

The solution would be to add another check in the ccTouchBegan function in CCControlButton.h

ie,

bool CCControlButton::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
    if (!isTouchInside(pTouch) || !isEnabled() || !isVisible())
    {
        return false;
    }

    //rest of the code....
}

should be changed to,

bool CCControlButton::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
    if (!isTouchInside(pTouch) || !isEnabled() || !isVisible() || !hasVisibleParents() )
    {
        return false;
    }

   //rest of the code...
}

Thanks

I think the current behavior is fine, reason is that you might want to use MenuItem like classes to create zones to listen to touch

Hi Hao,

Let me explain my use case,

I have a CCLayer called MenuBar in which i have 2 Layers MainMenuLayer and GameMenuLayer (with the same size and exactly below one another) but just one of them is visible at once,

Each layer has a button, which will change the view of the rest of the screen, and hide itself, and show the other…
Now say I click on GameMenuLayer’s button, now it should hide GameMenuLayer and show MainMenuLayer, which is happening, but when i click again, the GameMenuLayer’s handler is called, but that is not what is expected.

Thanks

Hao Wu wrote:

I think the current behavior is fine, reason is that you might want to use MenuItem like classes to create zones to listen to touch

Usually, I won’t to invisible the layer, just remove it from scene or layer’s parent node, kept in somewhere, and add it any time.
After the layer not exists on scene, the button won’t accept any event.