我正在用SpriteKit制作一个游戏,在这个游戏的主菜单中有一个SK3DNode,它包含一个设计用来包含旋转行星的SCNScene。我把它设成这样
//create scene
SCNScene *planetScene = [[SCNScene alloc] init];
SCNSphere *planet = [SCNSphere sphereWithRadius:2.0];
planet.firstMaterial.diffuse.contents = [UIImage imageNamed:@"Planet_2_d.png"];
SCNNode *plNode = [SCNNode nodeWithGeometry:planet];
[planetScene.rootNode addChildNode:plNode];
//animate planet
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"rotation"];
rotationAnimation.toValue = [NSValue valueWithSCNVector4:SCNVector4Make(0, 1, 0, M_PI * 2)];
rotationAnimation.duration = 6; // One revolution in ten seconds.
rotationAnimation.repeatCount = FLT_MAX; // Repeat the animation forever.
[plNode addAnimation:rotationAnimation forKey:nil]; // Attach the animation to the node to start it.
//create and add sprite kit node
SK3DNode *planetNode = [[SK3DNode alloc] initWithViewportSize:CGSizeMake(125, 125)];
planetNode.scnScene = planetScene;
planetNode.position = CGPointMake(loadGameButton.position.x - 200, CGRectGetMidY(self.frame));
planetNode.autoenablesDefaultLighting = YES;
planetNode.playing = YES;
id s1 = [planetNode valueForKey:@"_scnRenderer"];
NSLog(@"%@", s1);
[self addChild:planetNode];这是按计划进行的,除了行星做的不仅仅是旋转。除了旋转外,它还会放大和移出。在上面的代码中,我看不到任何东西会导致它以这种方式运行。我怎样才能让地球旋转而不是缩放呢?
发布于 2015-03-29 18:10:34
这个问题是通过在这样的场景中增加一个摄像机来解决的。
SCNCamera *camera = [SCNCamera camera];
camera.xFov = 0;
camera.yFov = 0;
camera.zNear = 0.0;
camera.zFar = 10.0;
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = camera;
cameraNode.position = SCNVector3Make(0, 0, 3);
[planetScene.rootNode addChildNode:cameraNode];
planetNode.pointOfView = cameraNode;https://stackoverflow.com/questions/29325153
复制相似问题