tags:

views:

99

answers:

1

I am having trouble finding a tutorial on CCCamera. And have even heard from others there is no CCCamera tutorial. But, to the point, the thing that I really want to know is simply: How do I move the coordinates of the cammera? I tried this after looking at the reference:

  CCCamera *myCam = [[CCCamera alloc] init];
  [myCam setCenterX:10000 centerY:10000 centerZ:0];

This doesn't give any warnings, crashes or anything like that, but, I suspected not to see anything because of what I put it in my init (look at the "//" comments in my code for a summary of whats going on):

-(id) init {
 if ( (self=[super init]) ) {
  isTouchEnabled = YES;

            //Make the characters and joystick here
  character = [CCSprite spriteWithFile: @"character.png"];
  character.position = ccp(50,100);
  [self addChild:character];


  leftJoy = [[[SneakyJoystickSkinnedBase alloc] init] autorelease];
  leftJoy.position = ccp(64,64);

  leftJoy.backgroundSprite = [ColoredCircleSprite circleWithColor:ccc4(255, 0, 0, 128) radius:32];
  leftJoy.thumbSprite = [ColoredCircleSprite circleWithColor:ccc4(0, 0, 255, 200) radius:16];

  leftJoy.joystick = [[SneakyJoystick alloc] initWithRect:CGRectMake(0,0,128,128)];
  leftJoystick = [leftJoy.joystick retain];
  [self addChild:leftJoy];

            //Camera should go way out and not see the other two things.
  CCCamera *myCam = [[CCCamera alloc] init];
  [myCam setCenterX:10000 centerY:10000 centerZ:0];

  [self schedule:@selector(tick:)];
 }
 return self;
}

You will need SneakyInput to run this. This question is similar but, it is only should I use the camera or not, not: How do I move the camera? Thanks in advanced for you help!

A: 

I noticed that often times cocos2d developers want to move the camera when it's actually much easier to simply move the layer containing the objects that should be moved. Many games like Canabalt, Super Turbo Action Pig and other scrolling games don't move the camera over the scene, they move the objects instead.

This has the added advantage that you can work with screen coordinates as opposed to mapping world to screen coordinates. Also scaling and rotating is much simpler without CCCamera.

Anyway, if you really need to use the CCCamera, you need to set both the center and the eye. From the top of my head:

CCCamera *myCam = [[CCCamera alloc] init];
[myCam setCenterX:10000 centerY:10000 centerZ:0];
[myCam setEyeX:10000 centerY:10000 centerZ:[CCCamera getZEye]];
GamingHorror
It still doesn't work. Your code without any edits crashes. Then, I thought you probably meant `[myCam setEyeX:10000 eyeY:10000 centerZ:[CCamera getZEye];` for your last line but, I can still see everything just like before without that statement.
thyrgle