我正在尝试将触摸位置从 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 层。