gpt4 book ai didi

ios - 正确链接 HUDLayer 到 GameplayLayer

转载 作者:行者123 更新时间:2023-11-29 04:22:39 26 4
gpt4 key购买 nike

我正在尝试将触摸位置从 GameplayLayer 传递到 HUDLayer 以查看用户是否按下控制按钮。

HudLayer.mm

-(void) handleTouchAtLocation:(CGPoint) location {
NSLog(@"Touch passed to HUD");
}

游戏玩法.mm

enum {
kHudLayer = 2;
};

+(CCScene *) scene {
CCScene *scene = [CCScene node];
HudLayer *hud = [HudLayer node];
[scene addChild:hud z:kHudLayer];
GameplayLayer *layer = [GameplayLayer node];
[scene addChild:layer];
return scene;
}

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for( UITouch *touch in touches ) {
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
[self handTouchAtPoint:(location)];
}
}

-(void) handleTouchAtPoint:(CGPoint)location {
NSLog(@"Touch At Point");
HudLayer *h1 = (HudLayer *)[self.parent getChildWithTag:kHudLayer];
[h1 handleTouchAtLocation:location];
}

HudLayer.h 导入到 GameplayLayer.h 中。我收到“Touch At Point”日志,但由于某种原因它没有进入 HUD 层..

最佳答案

唯一的解释是 self.parent 没有带有标签 kHudLayer 的子级。如果您在handleTouchAtPoint中设置断点,您会发现在执行getChildWithTag行后,h1为零。

关于ios - 正确链接 HUDLayer 到 GameplayLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12783823/

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