DNESS / cocos2d-iphone

Automatically exported from code.google.com/p/cocos2d-iphone
1 stars 0 forks source link

Hidden buttons (MenuItem) block touch on buttons under them #779

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add two buttons (e.g. MenuItemImage) at the same position
2. Hide the second one (visible = NO)
3. The first one doesn't get the touches, these are caught by the second
button, even if it is hidden.

What is the expected output? What do you see instead?
I think normally the touches on a button should not be caught if the button
is not visible.

What cocos2d version are you using ?
0.99.0-final

What iPhoneSDK are you using ?
3.1.3

Debug or Release ?
Both.

Does this happens on device ? or on the simulator ? or on both ?
Both.

Please provide any additional information below.
There is a very simple solution for this: add a visibility test in the
itemForTouch method in CCMenu, like this: 

-(CCMenuItem *) itemForTouch: (UITouch *) touch
{
    CGPoint touchLocation = [touch locationInView: [touch view]];
    touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];

    for( CCMenuItem* item in children_ ) {
        if (item.visible) { //ADDED VISIBILITY TEST HERE!
            CGPoint local = [item convertToNodeSpace:touchLocation];

            CGRect r = [item rect];
            r.origin = CGPointZero;

            if( CGRectContainsPoint( r, local ) )
                return item;
        }
    }
    return nil;
}

Original issue reported on code.google.com by marcu.ca...@gmail.com on 19 Feb 2010 at 8:06

GoogleCodeExporter commented 9 years ago
The same behavior should exist for disabled menu items. Neither disabled nor 
invisible menu items should block a touch, 
so that other items, or even other layers can handle them. My suggestion is to 
add the following after entering the for 
loop:

if (!item.visible || !item.isEnabled) {
    continue;
}

Original comment by jszatm...@gmail.com on 16 May 2010 at 3:15

GoogleCodeExporter commented 9 years ago

Original comment by ricardoq...@gmail.com on 17 May 2010 at 2:00

GoogleCodeExporter commented 9 years ago
fixed in:
http://github.com/cocos2d/cocos2d-iphone/commit/4278398cf7ff2eee40925dcfc6e5203a
91763eae

Original comment by ricardoq...@gmail.com on 17 May 2010 at 2:11