创建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;
网友评论