How do you make the Camera follow a sprite?

I have a 2D game where you are a bat and you are moving across the screen, I want to know how to make the camera follow the bat across the screen.

Hi @ShadowHunter12,instead of using a camera to follow the bat in your game, you can make use of the Follow action to make the game layer itself to follow the bat.Here’s an example which shows how to use the Follow action -

auto someSprite = Sprite::create(“someFileName”);
auto followTheSprite = Follow::create(someSprite,Rect::ZERO);
this->runAction(followTheSprite);

Note that in the above example, when creating the Follow action the second parameter in the create function can be replaced with any other Rect value so as to restrict the Follow action to that boundary only.

5 Likes