有没有办法在SceneKit场景中包含SpriteKit场景?

时间:2014-11-28 15:52:04

标签: sprite-kit scenekit

我想知道是否可以在SceneKit场景中包含SpriteKit场景,如果是,那该怎么做?

2 个答案:

答案 0 :(得分:9)

是的!

您可以在场景工具包中将精灵套件场景(SKScene)指定为材质属性contentsSCNMaterialProperty)。

答案 1 :(得分:2)

我遇到了一些关于这个确切主题的问题,并且似乎没有很多实际的代码示例,所以这里是另一个。希望这很有用:

SKSpriteNode *someSKSpriteNode;

// initialize your SKSpriteNode and set it up..

SKScene *tvSKScene = [SKScene sceneWithSize:CGSizeMake(100, 100)];
tvSKScene.anchorPoint = CGPointMake(0.5, 0.5);
[tvSKScene addChild:someSKSpriteNode];

// use spritekit scene as plane's material

SCNMaterial *materialProperty = [SCNMaterial material];
materialProperty.diffuse.contents = tvSKScene;

// this will likely change to whereever you want to show this scene.
SCNVector3 tvLocationCoordinates = SCNVector3Make(0, 0, 0);

SCNPlane *scnPlane = [SCNPlane planeWithWidth:100.0 height:100.0];
SCNNode *scnNode = [SCNNode nodeWithGeometry:scnPlane];
scnNode.geometry.firstMaterial = materialProperty;
scnNode.position = tvLocationCoordinates;

// Assume we have a SCNCamera and SCNNode set up already.

SCNLookAtConstraint *constraint = [SCNLookAtConstraint lookAtConstraintWithTarget:cameraNode];
constraint.gimbalLockEnabled = NO;
scnNode.constraints = @[constraint];

// Assume we have a SCNView *sceneView set up already.
[sceneView.scene.rootNode addChildNode:scnNode];