cocos2dx-让CCLayer随着英雄移动而移动

void HelloWorld::setCenterOfScreen(CCPoint p)
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();

	int x = MAX(p.x, s.width / 2);
	int y = MAX(p.y, s.height / 2);

	x = min(x, map->getMapSize().width * map->getTileSize().width - s.width/2);
	y = min(y, map->getMapSize().height * map->getTileSize().height - s.height/2);

	CCPoint goodPoint = ccp(x, y);
	CCPoint centerOfScreen = ccp(s.width/2, s.height/2);
	CCPoint diffence = ccpSub(centerOfScreen, goodPoint);

	this->setPosition(diffence);
}

转载于:https://www.cnblogs.com/tqj-zyy/archive/2013/03/17/4559810.html

你可能感兴趣的:(cocos2dx-让CCLayer随着英雄移动而移动)