How to use new Camera system?

How to use new Camera system?
0.0 0


Hi,I’m now develop game runner and trying to implement new camera system.
I’m using this Camera with following code

    _camera = Camera::create();

And I use this to move the camera.


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?

Box2d problem with perfomance

How it works? I’m so confused. It’s really different this new system.

girl = Sprite3D::create(filepath);
girl->setCameraMask((unsigned short)CameraFlag::USER1);

camera = Camera::create();

Here it’s still does nothing. I just want a simple 2d Camera.


You should set camera eye position at first.

A simplest example would be as follow:

    auto sprite = Sprite::create("HelloWorld.png");
    auto spritePos = Vec3(visibleSize.width/2 + origin.x,
                        visibleSize.height/2 + origin.y,
    // position the sprite on the center of the screen
    //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
    auto camera = Camera::createPerspective(60, (float)visibleSize.width/visibleSize.height, 1.0, 1000);
   //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));

CCTexture2d getName access violation

thanks, with this, I’m able to move the camera, without moving HUDLayer :smile:


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.

Particles Follow my vehicles Velocity ? Why?

Doesn’t the code above has give me two camera? CameraFlag::USER2 and CameraFlag::Default? I don’t have to specify the default camera do I?


default camera is created at Director::setProjection()


I see, so we can have multiple camera, and each of them give their point of view to the screen. That’s very convenient.

Thanks :smiley:


This just moves camera top sprite, if i move sprite, camera doesn’t move. How to make camera follow sprite ? Thanks dude


I’ve tried using it, and I set camera->setPositionX(40) and there are now 2 of my characters… the camera cloned him.

Also, should my main view be a Scene?


I had same issue, complete duplication all all scene sprites that follow camera. Crazy :frowning:
I’m just hoping the issue vanishes when i go back