Now we add the "star" block to the "Meta" on the map, and then add the following in the Code:
Bool Player: SetPlayerPosition (int x, int y) {CCSize spritesize = m_sprite-> getContentSize (); CCPoint dspoint = CCPoint (x + spritesize. width/2, y); CCPoint tiledpos = tileCoordForPosition (ccp (dspoint. x, dspoint. y); CCLOG ("tiled x = % f, y = % f", tiledpos. x, tiledpos. y); int tiledchild = meta-> tileGIDAt (tiledpos); if (tiledchild! = 0) {CCDictionary * propertydict = m_map-> propertiesForGID (tiledchild); const CCString * prop = propertydict-> valueForKey ("colpolicable "); if (prop-> m_sString.compare ("true") = 0) {x-= 1; y-= 1; // return false ;} const CCString * props = propertydict-> valueForKey ("star"); if (props-> length ()> 0 & props-> m_sString.compare ("true") = 0) {CCTMXLayer * barrier = m_map-> layerNamed ("barrier"); barrier-> removeTileAt (tiledpos);} Entity: SetPlayerPosition (x, y); SetViewPointByPosition (); return true ;}
In this way, when the protagonist moves to the stars, the stars will disappear.