I've been working on my first game with Cocos2D, and I've come across a question that Google doesn't seem to have an answer for. Is cocos2D like Flash, where the camera is fixed and in order to scroll a world you must move all the background things around, or is there a way to move the cocos2D camera (keep everythings X and Y coords static, just add to the camera's X and everything scrolls to the right)? It stands to reason that if Cocos2D is based in OpenGL there would be a way to do that.
Camera Positioning
(9 posts) (5 voices)-
Posted 2 years ago #
-
If it helps anyone the APIs have a class called Camera, but the APIs are pretty unclear, and they say that the camera will be overridden by anyone setting the position variables.
Posted 2 years ago # -
We do this on our scene node:
[self.camera setCenterX:newCameraPosition.x centerY:newCameraPosition.y centerZ:0];
[self.camera setEyeX:newCameraPosition.x eyeY:newCameraPosition.y eyeZ:415];Posted 2 years ago # -
Thanks very much. Worked like a charm.
Posted 2 years ago # -
i used that code in TouchesMoved but it cannot move perfectly.
Posted 2 years ago # -
Is your map pretty huge ? What problems did you have ?
Posted 2 years ago # -
yes my map bigger than iPhone screen. not really big (15 x 10) screen size. i use the above code to move the map but it move reversely. what value do i need to hange here? Im in landscape mode:
currTouch is a currentTouchLocation.
I update My camera and call updateCamera function each time I move the screen by implementing the ccTouchesMoved method:
-(void)updateCamera
{
[self.camera setCenterX:currTouch.x-80 centerY:currTouch.y+80 centerZ:0];
[self.camera setEyeX:currTouch.x-80 eyeY:currTouch.y+80 eyeZ:415];}
but it move reversely.
Posted 2 years ago # -
do you know what's the problem ?
Posted 2 years ago # -
dbgDraw.m_sprite = m_sprite; how you replaced this
Posted 2 years ago #
Reply
You must log in to post.