首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SCNSphere不适当旋转

SCNSphere不适当旋转
EN

Stack Overflow用户
提问于 2015-03-29 02:58:45
回答 1查看 457关注 0票数 0

我正在用SpriteKit制作一个游戏,在这个游戏的主菜单中有一个SK3DNode,它包含一个设计用来包含旋转行星的SCNScene。我把它设成这样

代码语言:javascript
复制
//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];

这是按计划进行的,除了行星做的不仅仅是旋转。除了旋转外,它还会放大和移出。在上面的代码中,我看不到任何东西会导致它以这种方式运行。我怎样才能让地球旋转而不是缩放呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-29 18:10:34

这个问题是通过在这样的场景中增加一个摄像机来解决的。

代码语言:javascript
复制
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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29325153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档