Cocos2d:触摸处理更改坐标系

时间:2013-05-14 04:54:15

标签: objective-c cocos2d-iphone

我有一个名为Gameplay图层的图层,它本身就是游戏中Tilemap的处理程序,在这一层我添加了玩家并将玩家添加到controlLayer中,因此玩家类可以由玩家控制。然后我将controlLayer添加为此类(Gameplay图层)的子项,问题是现在触摸的坐标(ccTouchesBegan ...)现在与tileMap的宽度和高度位于相同的坐标中。但我希望controlLayer独立并具有正常的480x320坐标,我该如何解决这个问题?

    controlLayer = [[DigGameControlLayer alloc]initWithObjectForPlayerControl:player];
    [self addChild:controlLayer];


- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
  for (UITouch *t in touches) {
    CGPoint touchLocation = [self convertTouchToNodeSpace:t];

1 个答案:

答案 0 :(得分:1)

我会回答我自己的问题,使用触摸自己视图的LocationInView效果很好

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *t in touches) {
        CGPoint touchLocation = [t locationInView:t.view];