There is.
Make a seperate camera object, and create a 'set up relative
positions' function in your main loop that updates the positions of
your game objects that are in world space, relative to the camera
location.
You'll need to set up visibility (hidden or not) depending on their
position inside of screen space (myObj.pos.x - myCamera.pos.x). So
you'll have a 'pos' variable inside your objects that is not the same
as the sprite's 'position' variable. You'll update your sprites
'position' variable with the world space calculation, only if the
object will be inside of your screen space.
So if your object is at world position 100, 0 and your camera is at
world position 90, 0, your object would be at 100 - 90 = 10, 0 in
world space. if it's leftmost point (assuming transform anchor = 0, 0)
is below 480 (assuming landscape mode) and its rightmost point is
above 0, it's in screen space.
As a sidenote, with your current setup you'll need to do this
visibility calculation anyhow for your game objects or performance
will start to suffer a great deal, so you may as well use it for the
objects that need it, and keep your score labels, etc. without the
extra processing.
I believe cocos2d has a built in point-to-world-space and
point-to-screen-space function in cocosNode, for objects that have
multiple children a large distance away from each other.
Chris.
On Thu, Jun 25, 2009 at 5:31 PM, <cocos2d-iphone-discuss@gamesforfood.cl> wrote:
> unigee says:
>
> Hi everyone,
>
> I am currently building a game that is on a continuous scroll across the
> level.
>
> I am wondering what are your methods to handle the scrolling, do you
> actually reposition all the content of the level, or simply move the camera?
>
> The way I have done it is by moving the camera, because it seems 'right' and
> easier
>
> The only issue I have is, when I need to create overlap sprites that always
> need to be in the boundary of the device's screen (think a score label etc),
> I need to continually calculate the position of said sprites and redraw them
> at the correct place, taking account of the camera's location.
> Is there an better way at doing this?
>
> Thanks
>
> Read the whole thread.