首页 > 代码库 > 摄像机跟随主角移动

摄像机跟随主角移动

  1. void MPlayer::setMapPointByMplayer()
  2. {
  3. Size visableSize = Director::getInstance()->getVisibleSize();
  4. Size mapTileNum = getGameMap()->getMapSize();
  5. Size tiledSize = getGameMap()->getTileSize();
  6. //世界大小 2.x CCSizeMake
  7. Size mapSize = Size(mapTileNum.width * tiledSize.width, mapTileNum.height * tiledSize.height);
  8. Point mplayerPoint = mSprite->getPosition();
  9. float x = mplayerPoint.x > visableSize.width / 4 ? mplayerPoint.x : visableSize.width / 4;
  10. x = x < mapSize.width - visableSize.width*.8 ? x : mapSize.width - visableSize.width*.8;
  11. float j = mapSize.width - visableSize.width*0.8;
  12. float y = mplayerPoint.y > visableSize.height / 4 ? mplayerPoint.y : visableSize.height / 4;
  13. y = y < mapSize.height / 2 ? y : mapSize.height / 2;
  14. Point desPoint = ccp(x, y);//目标点
  15. Point centerPoint = ccp(visableSize.width / 5, visableSize.height / 4);
  16. Point ritPoint = ccpSub(centerPoint, desPoint);
  17. getGameMap()->setPosition(ritPoint);
  18. }



来自为知笔记(Wiz)


摄像机跟随主角移动