2011-05-12 2 views
2

タイルマップを使ってタイルマップを作成しました。地図は40X40で、タイルセットのサイズは32X32です。ゲームでは、地図は下方にスクロールして、車が動いているとの錯覚を与えます。ゲーム中に地図をクリックすると、Y座標を取得できません。私はCocos2d座標系をタイルセットシステムに変換する必要があります。タイル地図が終わりに達すると、私は地図の始めに再び車を置きます。このように地図は無限に続きます。タイルされたアプリケーションの中で、私は取得する必要があるブロックの座標を見ることができます3,19ですが、そのタイルを反映するようにCocos2dの座標を変換する方法を理解するのは苦労しています。ここに私のコードです: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]; 
} 

答えて

0

チェックフォローリンク:

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

/** return the TMXLayer for the specific layer */ 
-(CCTMXLayer*) layerNamed:(NSString *)layerName; 

その後CCTMXLayerの方法に従うのいずれかを使用します。CCTMXTiledMapの方法でCCTMXLayerオブジェクトを取得するにはhttp://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps?s=tmx

てみてください