CCTMXTiledMap 相关

 

 

- (CGPoint) tileCoordForPosition:(CGPoint) position
{
    
    int x,y;
    if (WINSCALE == 1)
    {
        
        x = (position.x * 2) / self.tileMap.tileSize.width;
        y = ((self.tileMap.mapSize.height * self.tileMap.tileSize.height) - (position.y * 2)) / self.tileMap.tileSize.height;
        y = y < 0 ? 0 : y;
        
    }else
    {
        x = position.x / self.tileMap.tileSize.width;
        y = ((self.tileMap.mapSize.height * self.tileMap.tileSize.height) - position.y) / self.tileMap.tileSize.height;
     
    }
    
      
	return ccp(x,y);
}

 

 

 

 

 

 

 

 

 

- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    
    UITouch * touch = [touches anyObject];
    CGPoint mapLocation = [self.tileMap convertTouchToNodeSpace:touch];
    DLog("mapLocation:%@",NSStringFromCGPoint(mapLocation));
    
    
    
    
    CGPoint towerLoc = [self tileCoordForPosition: mapLocation];
    DLog("towerLoc:%@",NSStringFromCGPoint(towerLoc));
    

 

 

 

你可能感兴趣的:(ios,cocos2d,iPhone开发)