Tile map
-(void) Cctouchesbegan: (Nsset *) touches withevent: (uievent *) event{ccnode* node = [self Getchildbytag:tilemapnode]; cctmxtiledmap* Tilemap = (cctmxtiledmap*) node; Convert screen position to tile coordinate cgpoint touchlocation = [self locationfromtouch:[touches anyobject]; Cgpoint Tilepos = [self tileposfromlocation:touchlocation tilemap:tilemap];}//click Location-(cgpoint) Locationfromtouch: ( uitouch*) touch{Cgpoint touchlocation = [Touch locationinview: [Touch view]]; return [[Ccdirector Shareddirector] converttogl:touchlocation];} Location: Click Tilemap: Map-(Cgpoint) Tileposfromlocation: (cgpoint) site Tilemap: (cctmxtiledmap*) tilemap{// Click position + map coordinates (offset) cgpoint pos = ccpsub (location, tilemap.position); Scale size (off-screen, not scrolling) float scaledwidth = Tilemap.tilesize.width/cc_content_scale_factor (); float scaledheight = Tilemap.tilesize.height/cc_content_scale_factor (); Map coordinates pos.x = (int) (pos.x/scaledwidth); POS.Y = (int) ((TileMap.mapSize.height * tilemap.tilesizE.HEIGHT-POS.Y)/scaledheight); return POS;}
Converttogl
Considering the scale factor of the current scene
Right angle tile map coordinate conversion algorithm record (OC)