有谁知道为什么图层不跟随播放器?
void HelloWorld::update (float delta) {
cocos2d::Size winSize = cocos2d::Director::getInstance()->getWinSize();
this->_player->setPosition(this->_player->getPosition().x , this->_player->getPosition().y + (10 * delta));
this->_background->setPosition(this->_player->getPosition().x , this->_player->getPosition().y);
this->setPosition(this->_player->getPosition().x + (winSize.width / 2),
this->_player->getPosition().y + (winSize.height / 3)); // Follow The player
}
答案 0 :(得分:0)
该图层不会跟随您正在使用的代码的玩家。 Cocos2d-x为您提供了一个Follow action,您可以将其附加到节点,并在您想要制作的图层上运行。请参阅下面的示例代码。
auto followAction = Follow::create(playerNode, Rect());
// The Rect you give is the bounds the player can move before
// the camera (layer) starts following it. Giving empty rect will make sure the camera
// follows as soon as your player starts moving.
layerToFollow->runAction(followAction);
上面的代码会导致layerToFollow在玩家四处移动时移动。我希望这会有所帮助。