我无法找到有关 CCCamera 的教程。甚至还收到 others 的来信没有 CCCamera 教程。但是,就这一点而言,我真正想知道的事情很简单:如何移动相机的坐标?我在查看引用资料后尝试了这个:
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类似,但是,只是我是否应该使用相机,而不是:如何移动相机?
最佳答案
我注意到,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]];
关于iphone - 移动CC相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3562720/