移动CCCamera

时间:2010-08-25 03:46:08

标签: iphone cocos2d-iphone

我无法在CCCamera上找到教程。甚至从others听到没有CCCamera教程。但是,到目前为止,我真正想知道的事情很简单:如何移动cammera的坐标?我看了参考文献后试过这个:

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

这不会给出任何警告,崩溃或类似的东西,但是,我怀疑没有看到任何东西,因为我把它放在我的init中(查看我的代码中的“//”注释以获得摘要什么事情发生了):

-(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;
}

您需要SneakyInput才能运行此功能。这个question是相似的,但是我应该不使用相机,而不是:我如何移动相机?

1 个答案:

答案 0 :(得分:3)

我注意到cocos2d开发人员经常想要移动相机,而实际上更容易移动包含应该移动的对象的图层。 Canabalt,Super Turbo Action Pig和其他滚动游戏等许多游戏都没有将摄像机移动到场景中,而是移动了物体。

这样做的另一个好处是,您可以使用屏幕坐标,而不是将世界映射到屏幕坐标。如果没有CCCamera,缩放和旋转也会更加简单。

无论如何,如果你真的需要使用CCCamera,你需要同时设置中心和眼睛。从头到尾:

CCCamera *myCam = [[CCCamera alloc] init];
[myCam setCenterX:10000 centerY:10000 centerZ:0];
[myCam setEyeX:10000 centerY:10000 centerZ:[CCCamera getZEye]];
相关问题