gpt4 book ai didi

ios - SCNSphere 无法正常旋转

转载 作者:行者123 更新时间:2023-11-29 02:10:35 26 4
gpt4 key购买 nike

我正在使用 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];

这按计划进行,除了行星不只是自转这一事实。除了旋转之外,它还可以放大和缩小。我在上面的代码中看不到任何会导致它以这种方式运行的内容。我怎样才能让行星只旋转而不缩放?

最佳答案

这个问题通过向场景中添加一个相机来解决,如下所示

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;

关于ios - SCNSphere 无法正常旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29325153/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com