2015-11-19 7 views
0

Кто-нибудь знает Почему слой не следует за игроком?Не следует за игроком по обновлению

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

Слой не будет следовать за игроком с помощью кода, который вы используете. 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 перемещаться всякий раз, когда ваш игрок перемещается. Надеюсь, это поможет.

 Смежные вопросы

  • Нет связанных вопросов^_^