【问题标题】:Is there a way to include a SpriteKit scene in a SceneKit Scene?有没有办法在 SceneKit 场景中包含 SpriteKit 场景?
【发布时间】:2015-01-27 07:40:49
【问题描述】:

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

【问题讨论】:

  • Scene Kit 场景中的 Sprite Kit 场景你想做什么?
  • @DavidRönnqvist 例如,我将有一个电视的 3D 节点,而我的 SpriteKit 场景将是电视的屏幕,因此它将位于平面节点上。

标签: sprite-kit scenekit


【解决方案1】:

是的,有!

您可以将 Sprite Kit 场景 (SKScene) 指定为 Scene Kit 中材质属性 (SCNMaterialProperty) 的 contents

【讨论】:

  • 您还可以使用 SpriteKit SKScene 作为 overlay 覆盖整个 SceneKit 场景。您可以使用SK3DNode 将 SceneKit 内容放入 SpriteKit 场景中。不过,我还没有尝试查看您可以达到多少级别的 SceneKit-in-SpriteKit-in-SceneKit-etc。 :)
  • 它可以工作,但我的 SKScene 没有在 SCNGeometry 对象上播放。我只看到没有动画的静态纹理。它应该播放吗?
  • @RuslanK - 它没有播放,检查 SKScene.isPaused 是否设置为 false
【解决方案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];

【讨论】:

    猜你喜欢
    • 2016-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    相关资源
    最近更新 更多