I have two overlapping buttons called B1 and B2. (The first has width 80 and the second 160 pixels. Both have height 24 pixels.) A part of B2 overlaps B1. B2 has higher z-order so it's on top. To my surprise, when I click on the overlapping area the button B1 is activated. I think that it would be appropriate to activate button B2, since it's on top. That is how it functions in real world, and that is how users would expect it to be. Why this awkward behavior and and how do I fix it? The code is below. Thanks Bob
// HelloWorldLayer.h
#import "cocos2d.h"
@interface HelloWorld : CCLayer
{
}
+(id) scene;
@end
// HelloWorldLayer.m
#import "HelloWorldScene.h"
@implementation HelloWorld
+(id) scene
{
// create a 'scene' and add a layer to it
CCScene *scene = [CCScene node];
HelloWorld *layer = [HelloWorld node];
[scene addChild: layer];
return scene;
}
- (void)b1Tapped:(id)sender {
NSLog(@"b1Tapped");
}
- (void)b2Tapped:(id)sender {
NSLog(@"b2Tapped");
}
-(void) createButtons
{
// button B1
CCMenuItem *b1MenuItem = [CCMenuItemImage itemFromNormalImage:@"B1.png" selectedImage:@"B1Sel.png" target:self selector:@selector(b1Tapped:)];
b1MenuItem.position = ccp(60, 60);
// button B2
CCMenuItem *b2MenuItem = [CCMenuItemImage itemFromNormalImage:@"B2.png" selectedImage:@"B2Sel.png" target:self selector:@selector(b2Tapped:)];
b2MenuItem.position = ccp(150, 60);
// add buttons to a menu
CCMenu *buttonMenu = [CCMenu menuWithItems:b1MenuItem, b2MenuItem, nil];
buttonMenu.position = CGPointZero;
[self addChild:buttonMenu];
}
-(id) init
{
if( (self=[super init] )) {
[self createButtons];
}
return self;
}
- (void) dealloc
{
[super dealloc];
}
@end