Aaron Murgatroyd
Aaron Murgatroyd

Reputation: 1546

WKInterfaceSKScene.Init() deprecated from WatchOS 6

I recently converted my Storyboard SpriteKit WatchOS app from Storyboards to SwiftUI, in one part of my code I use the WKInterfaceSKScene.texture method to render some SKNodes to a texture for use later on in my game.

Unfortunately after the conversion you no longer have a WKInterfaceSKScene object as part of the view, but I realized that I can just create one using the WKInterfaceSKScene.init() initializer, this seems to work great, however, the init initializer is now deprecated and I assume will be removed in a future WatchOS version.

The warning is:

'init()' was deprecated in watchOS 7.0: Use SpriteKit.SpriteView instead.

Unfortunately SpriteView does not seem to have a similar method to render an SKNode to a texture.

I tried finding a different way of rendering SKNodes to a texture without using the WKInterfaceSKScene object but can’t find one, does anybody know how to do this on watchOS 9 without utilizing deprecated functionality?

WKInterfaceSKScene init() - https://developer.apple.com/documentation/watchkit/wkinterfaceskscene/3141929-init

WKInterfaceSKScene texture() - https://developer.apple.com/documentation/watchkit/wkinterfaceskscene/1650802-texture

Thank you.

Upvotes: 1

Views: 200

Answers (1)

user16930239
user16930239

Reputation: 9808

in SpriteKit all visible nodes are automatically rendered into textures (per documentation)

An SKTexture object is created and attached to the node. This texture object automatically loads the texture data whenever the sprite node is in the scene, is visible, and is necessary for rendering the scene. Later, if the sprite is removed from the scene or is no longer visible, SpriteKit can delete the texture data if it needs that memory for other purposes. This automatic memory management simplifies but does not eliminate the work you need to do to manage art assets in your game.

Upvotes: 1

Related Questions