In a horizontal game, to move the screen as the genie moves, you must first understand the changes and changes in the problem:
Unchanged: map location;
Change: the location of the genie, the location of the screen (or the location of the layer;
Therefore, a rolling map is actually a layer rolling;
First, you must know the two methods of map (CCTMXTileMap:
1. map-> getMapSize (): number of map Blocks
2. map-> getTileSize (): the width and height of each graph Block
Further analysis changes:
The genie moves first, and the screen is adjusted according to the coordinates of the genie moves;
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + samples/samples + q8HptcTX + samples/VwdTIy6OsxuS0 + samples + 6zUKx36Osy/ pushed + pushed + q8HptcS0udax1/pushed + q8Hp1/pushed/P1Mi709DS1M/CyP3W1sfpv/pushed/ycTc0tG + pushed/pushed + pushed PC9wPgo8cHJlIGNsYXNzPQ = "brush: java; "> void GameLayer: update (float dt) {this-> _ hero-> updateDesiredPosition (dt ); // set the hero position float posX = MIN (this-> _ tilemp-> getMapSize (). width * this-> _ tilemp-> getTileSize (). width-this-> _ hero-> _ centerToSides, MAX (this-> _ hero-> _ centerToSides, this-> _ hero-> _ desiredPosition. x); float posY = MIN (3 * this-> _ tilemp-> getTileSize (). height + this-> _ hero-> _ centerToBottom, MAX (_ hero-> _ centerToBottom, _ hero-> _ desiredPosition. y); this-> _ hero-> setPosition (ccp (posX, posY); // map rolling CCSize winSize = CCDirector: sharedDirector ()-> getWinSize (); int x = MAX (_ hero-> getPositionX (), winSize. width/2); int y = MAX (_ hero-> getPositionY (), winSize. height/2); x = MIN (x, (this-> _ tilemp-> getMapSize (). width * this-> _ tilemp-> getTileSize (). width)-winSize. width/2); CCPoint actualPosition = ccp (x, y); CCPoint centerOfView = ccp (winSize. width/2, winSize. height/2); CCPoint viewPoint = ccpSub (centerOfView, actualPosition); this-> setPosition (viewPoint );}}
Code reference, from: Example.