gpt4 book ai didi

iphone - 吞下触摸,除非触摸我当前层的 child

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:32:45 24 4
gpt4 key购买 nike

我正在使用 CCLayer 编写暂停菜单。我需要层来吞下触摸,这样你就不能按下下面的层,但是我还需要能够使用暂停层本身的按钮。

我可以让图层吞下触摸,但菜单也不起作用。

这是我的代码:

pauseLayer.m

#import "PauseLayer.h"

@implementation PauseLayer

@synthesize delegate;

+ (id) layerWithColor:(ccColor4B)color delegate:(id)_delegate
{
return [[[self alloc] initWithColor:color delegate:_delegate] autorelease];
}

- (id) initWithColor:(ccColor4B)c delegate:(id)_delegate {
self = [super initWithColor:c];
if (self != nil) {

NSLog(@"Init");
self.isTouchEnabled = YES;
CGSize wins = [[CCDirector sharedDirector] winSize];

delegate = _delegate;
[self pauseDelegate];

CCSprite * background = [CCSprite spriteWithFile:@"pause_background.png"];

[self addChild:background];

CCMenuItemImage *resume = [CCMenuItemImage itemFromNormalImage:@"back_normal.png"
selectedImage:@"back_clicked.png"
target:self
selector:@selector(doResume:)];
resume.tag = 10;
CCMenu * menu = [CCMenu menuWithItems:resume,nil];

[menu setPosition:ccp(0,0)];

[resume setPosition:ccp([background boundingBox].size.width/2,[background boundingBox].size.height/2)];

[background addChild:menu];

[background setPosition:ccp(wins.width/2,wins.height/2)];

}
return self;
}

-(void)pauseDelegate
{
NSLog(@"pause delegate");
if([delegate respondsToSelector:@selector(pauseLayerDidPause)])
[delegate pauseLayerDidPause];
}

-(void)doResume: (id)sender
{
if([delegate respondsToSelector:@selector(pauseLayerDidUnpause)])
[delegate pauseLayerDidUnpause];
[self.parent removeChild:self cleanup:YES];
}

- (void)onEnter {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES];
[super onEnter];
}

- (void)onExit {
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
return YES;
}

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

@end

最佳答案

为什么不直接禁用游戏层上的触摸?就像在 onEnter 方法中禁用游戏层上的触摸......和 ​​onExit 重新启用它们

有点像

-onEnter{
gameLayer.isTouchEnabled=NO;
....
}
-onExit{
gameLater.isTouchEnabled=YES;
...
}

你也不需要 CCTouchDispatcher

关于iphone - 吞下触摸,除非触摸我当前层的 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9899191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com