0
\$\begingroup\$
bool TestImageLoaderScene::init()
{
    if (!Scene::init())
        return false;

    bgLayer = Layer::create();
    this->addChild(bgLayer);

    BasicRUBELayer::init();

    playerNode = new PlayerNode;

    playerNode->addSprite();
    playerNode->addBodyToWorld(m_world);
    playerNode->addCircularFixtureToBody(0.2f);
    this->addChild(playerNode);

    bgLayer->runAction(Follow::create(playerNode));

    return true;
}

bgLayer is the layer that contains the background. The background has a static body and is 3500 x 2700 in size.

PlayerNode is an arbitrary class created to manage sprites and bodies together, and inherits node.

class PlayerNode : public cocos2d::Node
{
public:
    void addSprite();
    void addBodyToWorld(b2World* world);
    void addCircularFixtureToBody(float radius);

    void createFixture(b2Shape* shape);

    cocos2d::Sprite* getTextureSprite() { return playerTexture; }

protected:
    cocos2d::Sprite* playerTexture;
    b2Body* playerBody;
};

Any idea why it is not working? I am making a top-down view type game, and the phenomenon of not following the player's movement is very fatal.

please answer me. bad engilsh so sorry...

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.