Game Development Reference
In-Depth Information
Figure 10-10 . The orthogonal tilemap in the iPhone Simulator
Right now you can't do anything with the tilemap, but I'd like to change that. For ex-
ample, I'd like to be able to find the isWater tiles. I've added the
ccTouchesBegan method, as shown in Listing 10-1, to determine the tile that the
player is touching.
Listing 10-1 . Determining a Tile's Properties
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CCNode* node = [self getChildByTag:TileMapNode];
NSAssert([node isKindOfClass:[CCTMXTiledMap class]], @"not a CCTMXTiledMap");
CCTMXTiledMap* tileMap = (CCTMXTiledMap*)node;
// Get the position in tile coordinates from the touch location
CGPoint touchLocation = [self locationFromTouch:touches.anyObject];
CGPoint tilePos = [self tilePosFromLocation:touchLocation tileMap:tileMap];
// Check if the touch was on water (e.g., tiles with isWater property)
BOOL isTouchOnWater = NO;
CCTMXLayer* eventLayer = [tileMap layerNamed:@"GameEventLayer"];
int tileGID = [eventLayer tileGIDAt:tilePos];
if (tileGID ! = 0)
{
 
 
 
Search Nedrilad ::




Custom Search