When I tap AdView, CCMenuItem respond

201 Views Asked by At

I'm using kobold2d v2.1.0 and added AdMob Mediation SDK to my project according to Google's instructions.

I created AdViewController and added its view to rootViewController.view.

AdViewController.m:

-(void)viewDidLoad
{
    [super viewDidLoad];

    // Initialize the banner at the bottom of the screen.
    CGPoint origin = CGPointMake(0.0,
                     self.view.frame.size.height -
                     CGSizeFromGADAdSize(kGADAdSizeBanner).height);

    // Use predefined GADAdSize constants to define the GADBannerView.
    self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
                                               origin:origin];

    // before compiling.
    self.adBanner.adUnitID = AD_UNIT_ID;
    self.adBanner.delegate = self;
    [self.adBanner setRootViewController:self];
    [self.view addSubview:self.adBanner];
    self.adBanner.center =
    CGPointMake(self.view.center.x, self.adBanner.center.y);
    [self.adBanner loadRequest:[self createRequest]];
}

AppDelegete.m

-(void) initializationComplete
{
    adViewController = [[AdViewController alloc] init];
    [self.rootViewController.view addSubview:adViewController.view];
}

-(id) alternateView
{
    // we want to be a dummy view the self.view to which we add the glView plus all other UIKit views
    KKAppDelegate* appDelegate = (KKAppDelegate*)[UIApplication sharedApplication].delegate;

    // add a dummy UIView to the view controller, which in turn will have the glView and later other UIKit views added to it
    CGRect bounds = [appDelegate.window bounds];
    UIView* dummyView = [[UIView alloc] initWithFrame:bounds];

    [dummyView addSubview:[CCDirector sharedDirector].view];

    return dummyView;
}

When I tap Ad area before Ad is displayed, remotely located CCMenuItem is pressed as if I tap the CCMenuItem.

Please look at this

image

I think this is related to this question, but I do not know how to resolve it.

Please let me know how to prevent CCMenuItem to respond to the tap of the remote location.

I'm sorry I'm not good at English.

1

There are 1 best solutions below

0
On

I solved the problem by changing -(CCMenuItem *) itemForTouch: (UITouch *) touch Method in CCMenu.m.

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

    .......

}

Before change [touch view] is AdView, so CCMenu got wrong coordinates.

I was referring to this question.