美文网首页
OC SCNPlane播放视频

OC SCNPlane播放视频

作者: 升哥_d84b | 来源:发表于2020-11-23 15:22 被阅读0次

    创建Game项目

    引用#import<SpriteKit/SpriteKit.h>

    以下全部代码:

        SCNScene *scene = [SCNScene sceneNamed:@"art.scnassets/ship.scn"];

        // create and add a camera to the scene

        SCNNode*cameraNode = [SCNNodenode];

        cameraNode.camera= [SCNCameracamera];

        [scene.rootNodeaddChildNode:cameraNode];

        // place the camera

        cameraNode.position=SCNVector3Make(0,0,15);

        // create and add a light to the scene

        SCNNode*lightNode = [SCNNodenode];

        lightNode.light= [SCNLightlight];

        lightNode.light.type = SCNLightTypeOmni;

        lightNode.position=SCNVector3Make(0,10,10);

        [scene.rootNodeaddChildNode:lightNode];

        // create and add an ambient light to the scene

        SCNNode*ambientLightNode = [SCNNodenode];

        ambientLightNode.light= [SCNLightlight];

        ambientLightNode.light.type = SCNLightTypeAmbient;

        ambientLightNode.light.color= [UIColordarkGrayColor];

        [scene.rootNodeaddChildNode:ambientLightNode];

        // retrieve the ship node

        SCNNode *ship = [scene.rootNode childNodeWithName:@"ship" recursively:YES];

        // animate the 3d object

        [shiprunAction:[SCNAction repeatActionForever:[SCNAction rotateByX:0 y:2 z:0 duration:1]]];

        // retrieve the SCNView

        SCNView*scnView = (SCNView*)self.view;

        // set the scene to the view

        scnView.scene= scene;

        // allows the user to manipulate the camera

        scnView.allowsCameraControl = YES;

        // show statistics such as fps and timing information

        scnView.showsStatistics=YES;

        // configure the view

        scnView.backgroundColor= [UIColorblackColor];

        // add a tap gesture recognizer

        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];

        NSMutableArray*gestureRecognizers = [NSMutableArrayarray];

        [gestureRecognizersaddObject:tapGesture];

        [gestureRecognizersaddObjectsFromArray:scnView.gestureRecognizers];

        scnView.gestureRecognizers= gestureRecognizers;

        SCNNode*boxNode = [SCNNodenode];

        SCNPlane*plane = [SCNPlaneplaneWithWidth:16height:9];

        boxNode.geometry= plane;

        [boxNode.geometry.firstMaterial setDoubleSided:YES];

        boxNode.position=SCNVector3Make(0,0, -15);

        boxNode.eulerAngles=SCNVector3Make(0,M_PI,0);

        [scnView.scene.rootNodeaddChildNode:boxNode];

        NSURL*url = [[NSBundlemainBundle]URLForResource:@"带你到中国宣传视频短版本的副本.mov"withExtension:nil];

        SKVideoNode * videoNode = [SKVideoNode videoNodeWithURL:url];

        videoNode.size=CGSizeMake(1600,900);

        videoNode.position=CGPointMake(videoNode.size.width/2.0, videoNode.size.height/2.0);

        videoNode.zRotation=M_PI;

        SKScene*skScene = [SKScenesceneWithSize:videoNode.size];

        [skSceneaddChild:videoNode];

        plane.firstMaterial.diffuse.contents = skScene;

        [videoNodeplay];

        scnView.allowsCameraControl = YES;

    相关文章

      网友评论

          本文标题:OC SCNPlane播放视频

          本文链接:https://www.haomeiwen.com/subject/kscviktx.html