0
我试图将GameplayLayer的触摸位置传递给HUDLayer以查看用户是否按下了控制按钮。将HUDLayer正确链接到GameplayLayer
HudLayer.mm
-(void) handleTouchAtLocation:(CGPoint) location {
NSLog(@"Touch passed to HUD");
}
Gameplay.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导入。 我得到了“触摸点”的日志,但它不会通过对HUD层出于某种原因..
你是对的,它是零。 – iamruskie
取出.parent做了伎俩。我想我有点混在那里。感谢 – iamruskie
你似乎将这个常量用作zOrder,而不是标签。因此,如果它现在“有效”,请注意将来对父对象添加对象的顺序的更改。 – YvesLeBorg