init函数
定时刷新
this->schedule(schedule_selector(Role::camera_update),0.016f);
updata函数
void Role::camera_update(float dt){
setMapPointByRole();
}
镜头移动
void Role::setMapPointByRole(){
float x1 = getGameMap()->getPositionX();
CCSize visableSize = CCDirector::sharedDirector()->getVisibleSize();
//地图尺寸
CCSize mapTiledNum = getGameMap()->getMapSize();
CCSize tiledSize = getGameMap()->getTileSize();
CCSize mapSize = CCSizeMake(mapTiledNum.widthtiledSize.width,mapTiledNum.heighttiledSize.height);
CCPoint rolePoint = mSprite->getPosition();
// 人物横坐标跟可视区域的四分之一比较,超过则用人物的坐标,没超过则用四分之一坐标
float x = rolePoint.x > visableSize.width/4 ? rolePoint.x : visableSize.width/4;
x = x < mapSize.width-visableSize.width*.8 ? x : mapSize.width-visableSize.width*.8;
float y = rolePoint.y > visableSize.height/4 ? rolePoint.y : visableSize.height/4;
y = y < mapSize.height/2 ? y : mapSize.height/2;
CCPoint desPoint = ccp(x,y); //目标点
CCPoint centerPoint = ccp(visableSize.width/5,visableSize.height/4);
CCPoint rltPoint = ccpSub(centerPoint,desPoint);
getGameMap()->setPosition(rltPoint);
float x2 = getGameMap()->getPositionX();
}
我运行,人物Run ,跑出可视区域了,但是镜头却没有动, 求大神