Essentially, when I have one CCLayer
for background and platform sprites and another for player sprite and HUD, how should I go about calling CCFollow
if I want my camera to always center at the player with the HUD in the same layer moving accordingly as well?
Right now the background layer is a subclass of CCLayer
that has a CCSpriteBatchNode
for drawing objects in the environment. It contains an instance variable CCLayer *HudLayer
that has a CCMenu
and another CCSpriteBatchNode
for the player animation sprites. They are both direct children of a CCScene
, meaning HudLayer
is not a children of BackgroundLayer
. I'm now calling the CCFollow
as [self runAction:[CCFollow actionWithTarget:playerSprite worldBoundary:worldRect]]
where self
is the BackgroundLayer
.
The camera follows the box2d physics body of the player correctly, and the menu moves with it too, but whenever the camera moves, let's say to the right, the player sprite moves twice as fast to the right, leaving its physics body behind. So after moving to the right for a bit the playerSprite is outside of screen. playerSprite.pos
and playerSprite.position
seem to have nothing wrong though.
I've tried calling the CCFollow
in different places but either the HUD refuses to move or the camera won't move or the player moves weirdly. What's wrong with it?