Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 滑动CCMenu_Cocoa_Cocos2d Iphone - Fatal编程技术网

Cocoa 滑动CCMenu

Cocoa 滑动CCMenu,cocoa,cocos2d-iphone,Cocoa,Cocos2d Iphone,我有一个包含CCMenuItemImages的菜单(“myMenu”)。我想这个菜单来检测手指滑动和相应的幻灯片 我的问题是,CCMenuItemImages似乎吸收了触摸事件。当用户触摸CCMenuItemImages之外的菜单时,滑动工作正常,但当触摸这些图像时,滑动工作正常 我曾尝试将菜单项放在一个层中以检测触摸(参考答案),但这似乎也不起作用。知道为什么吗 +(id) scene { CCScene *scene = [CCScene node]; ModeMenuSce

我有一个包含
CCMenuItemImage
s的菜单(“myMenu”)。我想这个菜单来检测手指滑动和相应的幻灯片

我的问题是,
CCMenuItemImage
s似乎吸收了触摸事件。当用户触摸CCMenuItemImages之外的菜单时,滑动工作正常,但当触摸这些图像时,滑动工作正常

我曾尝试将菜单项放在一个层中以检测触摸(参考答案),但这似乎也不起作用。知道为什么吗

+(id) scene
{
    CCScene *scene = [CCScene node];
    ModeMenuScene *layer = [ModeMenuScene node];
    [scene addChild: layer];
    return scene;
}

-(id) init
{
    if( (self=[super init] )) {


        CGSize winSize = [[CCDirector sharedDirector] winSize];
        CCSprite *background = [CCSprite spriteWithFile:@"bg.png"];
        background.position=ccp(winSize.width/2,winSize.height/2);
        [self addChild:background];

        mode1 = [CCMenuItemImage itemFromNormalImage:@"Mode1.png" selectedImage: @"Mode1.png" target:self selector:@selector(goToMode1:)];
        mode1label = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Level 1 %d", n] dimensions:CGSizeMake(220,53) alignment:UITextAlignmentCenter fontName:@"Arial" fontSize:20.0];
        mode1label.color = ccc3(167,0,0);
        mode1label.position=ccp(55,-30);
        [mode1 addChild:mode1label];

    // here same kind of code to define mode2,mode3,mode4 (taken out to reduce size of code)

        myMenu=[CCMenu menuWithItems:mode1,mode2,mode3,mode4,nil];
        [myMenu alignItemsHorizontallyWithPadding:25];
        myMenu.position=ccp(winSize.width/2+40,180);
        menuLayer = [CCLayer node];
        [menuLayer addChild:myMenu];
        [self addChild:menuLayer];

        [self enableTouch];

    }
    return self;
}

-(void) disableTouch{
    self.isTouchEnabled=NO;
    menuLayer.isTouchEnabled=NO;
}

-(void) enableTouch{
    self.isTouchEnabled=YES;
    menuLayer.isTouchEnabled=YES;
}


-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:[touch view]];
    if(location.y>100 && location.y<260) {
        draggingMenu=1;
        x_initial = location.x;
    }
    else draggingMenu=0;
}


-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:[touch view]];
    if(draggingMenu==1) {
        CGSize winSize = [[CCDirector sharedDirector] winSize];
        int x = myMenu.position.x+location.x-x_initial;
        x = MAX(0,x);
        x = MIN(x,winSize.width/2+40);
        myMenu.position=ccp(x,180);
        x_initial=location.x;
    }
}

- (void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    draggingMenu=0;
}


- (void)dealloc {
    [super dealloc];
}

@end
+(id)场景
{
CCScene*scene=[CCScene节点];
ModeMenuScene*层=[ModeMenuScene节点];
[场景添加子对象:层];
返回场景;
}
-(id)init
{
if((self=[super init])){
CGSize winSize=[[CCDirector sharedDirector]winSize];
CCSprite*background=[CCSprite spriteWithFile:@“bg.png”];
background.position=ccp(winSize.width/2,winSize.height/2);
[自我添加孩子:背景];
mode1=[CCMenuItemImage itemFromNormalImage:@“mode1.png”selectedImage:@“mode1.png”目标:自选择器:@selector(goToMode1:)];
mode1label=[CCLabelTF labelWithString:[NSString stringWithFormat:@“Level 1%d”,n]维度:CGSizeMake(220,53)对齐方式:UITextAlignmentCenter fontName:@“Arial”fontSize:20.0];
mode1label.color=ccc3(167,0,0);
模式1标签位置=ccp(55,-30);
[mode1 addChild:mode1标签];
//这里是定义mode2、mode3、mode4的同一种代码(取出以减小代码大小)
myMenu=[CCMenu menuWithItems:模式1、模式2、模式3、模式4、无];
[myMenu alignItemsHorizontallyWithPadding:25];
myMenu.position=ccp(winSize.width/2+40180);
menuLayer=[CCLayer节点];
[menuLayer addChild:myMenu];
[self-addChild:menuLayer];
[自启动触摸];
}
回归自我;
}
-(无效)禁止触摸{
self.isTouchEnabled=否;
menuLayer.isTouchEnabled=否;
}
-(无效)使能触摸{
self.isTouchEnabled=是;
menuLayer.isTouchEnabled=YES;
}
-(void)CCTouchesStart:(NSSet*)与事件接触:(UIEvent*)事件{
UITouch*touch=[触摸任何对象];
CGPoint location=[touch locationInView:[touch view]];
如果(location.y>100&&location.y通过添加:

-(void) registerWithTouchDispatcher
{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:NO];
}

问题是CCMenuItemImage会吞下触摸,并将高优先级设置为-128。因此,需要将优先级设置为
INT\u MIN+1

您在哪里添加了此代码?在包含CCMenuItemImage的CCScene类中,我也停留在同一点上