Now, if I do this, the HUD Layer, with scene as parent and Main Layer as siblings, is also moving.
How to make HUD Layer static? Earlier version will work with this concept. How to implement it correctly?
auto sprite = Sprite::create("HelloWorld.png");
auto spritePos = Vec3(visibleSize.width/2 + origin.x,
visibleSize.height/2 + origin.y,
0);
// position the sprite on the center of the screen
sprite->setPosition3D(spritePos);
//this is the layer, when adding camera to it, all its children will be affect only when you set the second parameter to true
this->setCameraMask((unsigned short)CameraFlag::USER2, true);
// add the sprite as a child to this layer
this->addChild(sprite);
auto camera = Camera::createPerspective(60, (float)visibleSize.width/visibleSize.height, 1.0, 1000);
camera->setCameraFlag(CameraFlag::USER2);
//the calling order matters, we should first call setPosition3D, then call lookAt.
camera->setPosition3D(spritePos + Vec3(0,0,800));
camera->lookAt(spritePos, Vec3(0.0,1.0,0.0));
this->addChild(camera);
In fact you’d better have two cameras,one is HUD-Layer-Camera(you can use default camera), another one is Main-Layer-Camera(or scene-camera). the object who is in the default camera will be drawn at the end, if you moved your Main-Layer-Camera you will not affect Main-Layer’s object.