【问题标题】:Does Not Follow Player on update更新时不关注玩家
【发布时间】:2015-11-19 03:02:04
【问题描述】:

有谁知道为什么图层不跟随玩家?

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 
}

【问题讨论】:

    标签: cocos2d-x cocos2d-x-3.0


    【解决方案1】:

    图层不会跟随播放器使用您正在使用的代码。 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 在你的玩家移动时移动。我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 2022-10-15
      • 1970-01-01
      • 2021-08-20
      • 2020-12-07
      • 1970-01-01
      • 1970-01-01
      • 2015-09-11
      相关资源
      最近更新 更多