What's the right method to keep a sprite in the center?

My game allows the player to control the airship fly around. To avoid the airship flying out of the screen, my game bind the airship in the center of the screen and move all the other sprites relative to the airship instead.

Say, I want to my move the airship by a vector (x, y), actually now it’s that all the other sprites move by (-x, -y) (by setPosition). But I was told there was a way to bind the airship always to the center, even though actually I was moving the airship. Is this true?

The reason why I ask the question is that I found when the airship collides with any others in the PhysicsWorld, it does move away the center, which is what I don’t wanna happen.

Thanks a lot.

There is a Follow action, which will do it for you. Apply to the parent layer and follow your airship.

Thanks. I though there was Camera originally. But I only find the test of OrbitCamera in v3.2 but no ActionCamera. I’m not sure is there a “Camera” in v3.2 that do what I want?

Thanks a lot.

Sorry, two more questions

Firstly, , how should I detect the touch after follow action?
Currently, my code is:

    Rect rect = getRectByPosition(_player);
    if (!rect.containsPoint(touch->getLocation())) return false;
    return true;

and the getRectByPosition function is:

Rect getRectByPosition(Sprite *sprite) {
    auto ret = Rect(sprite->getPositionX() - sprite->getContentSize().width / 2,
                    sprite->getPositionY() - sprite->getContentSize().height / 2,
                    sprite->getContentSize().width,
                    sprite->getContentSize().height );
    return ret;
}

But it doesn’t work any more.

Second,

If there’s only a follow action added by myself, does stopAllActions only stop the follow action or there is some other actions added by cocos2dx? I have this question because the scene will always be reload and I need to readd the follow function. Thus I want to stop all the previous added actions.

Thanks again.

AFAIK there was a Camera in some early version. Then the developers decided that the camera is redundant in the 2d engine, which is obviously a mistake. And now they are going to return it in v.3.4 or later.

Regarding the touches. You have to transform the touches from screen space to world space. There are examples how to do this on the internet and on this forum.

Pure Cocos2d-x doesn’t add any actions by itself.