Cocos2d iphone Cocos2d中垂直滚动游戏的平铺地图问题

Cocos2d iphone Cocos2d中垂直滚动游戏的平铺地图问题,cocos2d-iphone,Cocos2d Iphone,我使用平铺应用程序创建了一个平铺贴图。地图为40X40,瓷砖集大小为32X32。在游戏中,地图向下滚动,给人一种汽车在移动的错觉。当我在游戏中点击地图时,我很难得到Y坐标。我需要将Cocos2d坐标系转换为tileset坐标系。当平铺地图到达终点时,我再次将汽车放在地图的起点。这样,地图将无限延伸。在平铺应用程序中,我可以看到我需要获得的块的坐标,即3,19,但我很难弄清楚如何转换Cocos2d坐标以反映该平铺。这是我的密码: - (CGPoint)tileCoordForPosition:(C

我使用平铺应用程序创建了一个平铺贴图。地图为40X40,瓷砖集大小为32X32。在游戏中,地图向下滚动,给人一种汽车在移动的错觉。当我在游戏中点击地图时,我很难得到Y坐标。我需要将Cocos2d坐标系转换为tileset坐标系。当平铺地图到达终点时,我再次将汽车放在地图的起点。这样,地图将无限延伸。在平铺应用程序中,我可以看到我需要获得的块的坐标,即3,19,但我很难弄清楚如何转换Cocos2d坐标以反映该平铺。这是我的密码:

- (CGPoint)tileCoordForPosition:(CGPoint)position {

   int x = position.x / self.tiledMap.tileSize.width;

      int y1 = ((self.tiledMap.mapSize.height * self.tiledMap.tileSize.height) - position.y) / self.tiledMap.tileSize.height;

    return ccp(x, y1);
}

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

    CGPoint tileCoord = [self tileCoordForPosition:location];
}
选中以下链接:

尝试使用CCTMXTiledMap的方法获取CCTMXLayer对象:

/** return the TMXLayer for the specific layer */
-(CCTMXLayer*) layerNamed:(NSString *)layerName;
然后使用以下CCTMXLayer方法之一:

-(CCSprite*) tileAt:(CGPoint)tileCoordinate;
-(uint32_t) tileGIDAt:(CGPoint)tileCoordinate;
-(uint32_t) tileGIDAt:(CGPoint)pos withFlags:(BOOL) flags;
选中以下链接:

尝试使用CCTMXTiledMap的方法获取CCTMXLayer对象:

/** return the TMXLayer for the specific layer */
-(CCTMXLayer*) layerNamed:(NSString *)layerName;
然后使用以下CCTMXLayer方法之一:

-(CCSprite*) tileAt:(CGPoint)tileCoordinate;
-(uint32_t) tileGIDAt:(CGPoint)tileCoordinate;
-(uint32_t) tileGIDAt:(CGPoint)pos withFlags:(BOOL) flags;