I have been trying to render a node tree into an SKTexture
as a possible solution to another question here. I tried searching for an answer to this, and I came across one of Apple's Developer pages (view it here). It says the command which converts a node tree into an SKTexture
is this:
func texture(from node: SKNode) -> SKTexture?
Although, the code is incomplete since there is no code which executes the conversion of a node tree to an SKTexture
. Am I doing something wrong or what is the complete code that I should use to render a node tree into an SKTexture
.
Thanks for any advice, help, and answers!
texture(from:)
is an instance method ofSKView
that takes a node (with zero or more children) as a parameter and returns an optionalSKTexture
. Since the returned value is an optional, you'll need to unwrap it before using it.From
didMove(to:)
, you can use theview
parameter to create a textureFrom other methods in the
SKScene
subclass, use optional chainingYou can also render the portion of the node-tree's contents inside of a rectangle with