SceneKit_大神03_navigationbar上的3D文字
让学习成为一种习惯
就是一个普通的应用
拖拽一个view放在界面上,把它的类改成SCNView
引用一下
上一步,有红不要紧,因为你没有添加框架.
配置工程到此结束,简单吧
self.scnView.backgroundColor = [UIColor blackColor];
self.scnView.scene = [SCNScene scene];
SCNCamera *camera = [SCNCamera camera];
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = camera;
cameraNode.position = SCNVector3Make(0, 5, 10);
[self.scnView.scene.rootNode addChildNode:cameraNode];
SCNNode *lightNode = [SCNNode node];
lightNode.light = [SCNLight light];
lightNode.light.type = SCNLightTypeSpot;
lightNode.position = SCNVector3Make(0, 20, 20);
lightNode.rotation = SCNVector4Make(1, 0, 0, -M_PI/4);
[self.scnView.scene.rootNode addChildNode:lightNode];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(createTextNode) userInfo:nil repeats:true];
-(void)createTextNode{
// 创建字体
SCNText *text = [SCNText textWithString:@"我是弹幕" extrusionDepth:1];
text.firstMaterial.diffuse.contents = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1];
text.font = [UIFont systemFontOfSize:2];
text.firstMaterial.diffuse.contents = @"1.PNG";
//绑定到节点上
SCNNode *textNode =[SCNNode nodeWithGeometry:text];
// 随机节点位置
textNode.position = SCNVector3Make(-arc4random_uniform(30)+15, arc4random_uniform(20)+1, -100);
// 添加行为动画
SCNAction *moveAction = [SCNAction moveTo:SCNVector3Make(-2, 4, 10) duration:5];
SCNAction *removeFromSuper = [SCNAction removeFromParentNode];
SCNAction *customAction = [SCNAction sequence:@[moveAction,removeFromSuper]];
// 将节点添加到场景中去
[self.scnView.scene.rootNode addChildNode:textNode];
[textNode runAction:customAction];
}
运行效果:
让学习成为一种习惯