Custom camera draws sprites outside the screen

Custom camera draws sprites outside the screen


Hello, I’m on making a new 2D game with Cocos2d-x using C++. My game scene has a large space and it’s need a camera to move around it. But I can’t use just default scene camera, 'cause so-called UILayer will be affected by moving camera. So it’s necessary to add another one. I’ve read a lot of topics about using cameras and knowed out that it’s better to use default scene camera as immovable “UI camera” and create another one to move around game world. Moreover, I can subclass second camera and set up it the way i like it.

However, here comes a problem. When I use default camera as “world camera” sprites, which are gone outside the screen are not drawn. Draw calls and verticed match the number of sprites right at the moment on the screen. That’s good! But I can’t subclass default scene camera, cause’ it was automatically created by the scene. So I can’t customize it.

Okay, let’s use custom camera. It turned out, that when using custom camera as “world camera” sprites that are out of the screen don’t reduce draw calls and vertices!!! So it will draw whole my large world every frame!!!

I read and searched over lots of cocos2d-x source files but didn’t find the solution!

I need your help! How can I reduce draw calls using custom camera?

I’ll be very grateful for your help!!! )


Did you try with Follow ?
For example:



I’ve just tried out. Draw calls are reduced while sprites’re outside, but… Here’re some bugs drawn out!)

I can show you on example


Draw calls and vertices are good, but… You can’t see my finger, but it’s on black part of the screen while button “duo” thinks like it was clicked. I examined this phenomenon and knew out that “clicking button” commits when I click on position of button where it was before I started moving layer.


Are you using ui::Button for create the button?
The button is layer’s child? If the button is a child of the layer when you move the layer, the button should move ok :thinking:


Yes, all’s exactly you described :anguished: