Moving the camera


#1

Hi,

In cocos2D, I used the following code to move the camera in order to track a sprite accross the game layer:

`-(void)centerCamera:(CGPoint)center{

CGSize winSize = [CCDirector sharedDirector].winSize;
center.x -= (winSize.width / 2);
center.y -= (winSize.height / 2);

[self.camera setCenterX:center.x centerY:center.y centerZ:0];
[self.camera setEyeX:center.x eyeY:center.y eyeZ:1]; 

}`

I expected the following to achieve the same result; However, it doesn’t cause the camera to move around the game layer:
@
var MainLayer = cc.LayerColor.extend( {
// …
centerCamera: function(center){

var winSize = cc.Director.getInstance().getWinSize()

center.x = ;
center.y
= (winSize.height / 2);

this.getCamera().setCenterXYZ(center.x, center.y, 0);
this.getCamera().setEyeXYZ(center.x, center.y, 1);
},@

How is this supposed to work in CC2Dx-HTML5?

thanks!
J.


#2

Hi Jem,

Have you set the projection of cc.Director to cc.DIRECTOR_PROJECTION_3D?


#3

Hi,

Yes, I added that line when creating the scene:
cc.Director.getInstance().setProjection(cc.DIRECTOR_PROJECTION_3D);

That doesn’t help panning the camera with the above code. What’s the usual/recommended way to pan the camera please?

Thanks!