0

I don't know whats wrong, maybe because i'm using more layers?
I think that my other layer (sliding menu grid subclass is stealing the touches...) // // BGLayer.m // MainProject // // Created by NSSL1 on 8/30/12. // Copyright (c) 2012 MyCompanyName. All rights reserved. //

#import "BGLayer.h"
#import "GameManager.h"
#import "MainMenuLayer.h"

@interface BGLayer() 
-(void)displayBGMenu;
@end

@implementation BGLayer

-(void)backtomenu:(CCMenuItem*)itemPassedIn{
    CCLOG(@"why I can't reach here?");
    [[GameManager sharedGameManager] runSceneWithID:kMainMenuScene];} 
-(id)init {
    self = [super init];
    if (self != nil) {
        self.isTouchEnabled=YES;

        [self displayBGMenu];

    }
    return self;
}
    -(void)displayBGMenu{
        NSString* backLabelstring = [NSString stringWithFormat:@"Back to Menu"];
        CGSize screenSize = [CCDirector sharedDirector].winSize;
        //Shadow
        CCLabelTTF *backLabel = [CCLabelTTF labelWithString:backLabelstring fontName:@"Marker Felt" fontSize:32];
        backLabel.position=CGPointMake(screenSize.height*0.5f, screenSize.width*0.1f);
        backLabel.color = ccBLUE;

        CCMenuItem* backbtnitem=[CCMenuItemLabel itemWithLabel:backLabel target: self
                                                      selector:@selector(backtomenu:)];
        [backbtnitem setTag:21];
        menu = [CCMenu menuWithItems:backbtnitem ,nil];
        menu.position = CGPointMake((screenSize.width / 2), screenSize.height*0.1f);
        menu.tag = 200;
        [self addChild:menu z:20 tag:200];



    }



@end
Idan Banani
  • 131
  • 2
  • 13

1 Answers1

0

I had an issue with layers swallowing touches in the same type of class, and to avoid this someone suggested me to add this in the grid button item class init method:

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:YES];

The effect is that the class calling this method would not be greedy towards the parent's layer touch detector by detecting only the touches in its area, and would allow the user to scroll the menu in a smooth way as well as pressing other items in the parent layer (such as your menu).

mm24
  • 9,280
  • 12
  • 75
  • 170
  • you mean in the -(void) registerWithTouchDispatcher method at slidingmenugrid? its still doesn't work. (putting it at the init method causes exeption) – Idan Banani Sep 02 '12 at 16:21
  • I think Ill try this : CCMenuItemFont *menuItem1 = [CCMenuItemFont itemFromString:@"Menu" target:self selector:@selector(onMenu:)]; menuItem1.position = ccp(-20, -250); [menuGrid addChild:menuItem1 z:1 tag:0]; [self addChild:menuGrid]; – Idan Banani Sep 02 '12 at 16:27
  • actually i'm using this version http://apptinker.wordpress.com/2012/03/15/the-stacker-8-menus/#comment-41 , so it makes my life harder... – Idan Banani Sep 02 '12 at 16:29
  • I did mean what I said in the answer. I have not that clear the issue myself either but I just now that priority:-1 solves the issue as the other touches gets swallowed first by the upper layer. I can't help more than this so maybe might be more appropriate if someone else replies – mm24 Sep 06 '12 at 18:41