-
-
Save nashsu/8dbc8063933b2d16434bfaae6eb450dd to your computer and use it in GitHub Desktop.
adding a video in a SceneKit scene using a SpriteKit SKVideoNode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let spriteKitScene = SKScene(size: CGSize(width: 1276.0 / 2.0, height: 712.0 / 2.0)) | |
var videoSpriteKitNode:SKVideoNode? | |
let videoNode = SCNNode() | |
videoNode.geometry = SCNPlane(width: videoNodeWidth, height: videoNodeHeight) | |
// using SpriteKit scene with videonode inside | |
// | |
spriteKitScene.scaleMode = .AspectFit | |
videoSpriteKitNode?.position = CGPoint(x: spriteKitScene.size.width / 2.0, y: spriteKitScene.size.height / 2.0) | |
videoSpriteKitNode?.size = spriteKitScene.size | |
spriteKitScene.addChild(videoSpriteKitNode!) | |
videoNode.geometry?.firstMaterial?.diffuse.contents = spriteKitScene | |
videoNode.geometry?.firstMaterial?.doubleSided = true | |
// flip video upside down, so that it's shown in the right position | |
// | |
var transform = SCNMatrix4MakeRotation(Float(M_PI), 0.0, 0.0, 1.0) | |
transform = SCNMatrix4Translate(transform, 1.0, 1.0, 0) | |
videoNode.geometry?.firstMaterial?.diffuse.contentsTransform = transform | |
videoNode.position = SCNVector3(x: 0, y: 30, z: 7) | |
aSceneKitNode.addChildNode(videoNode) | |
videoSpriteKitNode?.play() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment