【问题标题】:Extracting a texture in watchOS 3在 watchOS 3 中提取纹理
【发布时间】:2016-07-16 21:58:04
【问题描述】:

我在我的 GameScene.swift 中使用 iOS 10.0 中的以下代码

    //Shape storage
    let playerShape = SKShapeNode(circleOfRadius: 10 )

...颜色设置等

    //Get the texture from shape node
    let playerTexture = view?.texture(from: playerShape)

相同的代码在 watchOS 3.0 中不起作用 Xcode 8.0 beta 2 对视图的抱怨:

Use of unresolved identifier 'view'

有谁知道 watchOS 中的视图相当于什么?

谢谢。

【问题讨论】:

  • 你用什么,我没见过view?.texture(from:SKNode) 我只见过view?.textureFromNode(SKNode)
  • WKInterfaceSKScene 是你用于 watchOS 的,skview 不存在
  • @Knight0fDragon 感谢 cmets。 - view?.texture(from:SKNode) 可能是因为 Swift 3 - 我在 'class GameScene: SKScene' 中执行此操作,这也不允许我将其定义为 WKInterfaceSKScene。

标签: swift sprite-kit watchkit xcode8 ios10


【解决方案1】:

如上所述,Apple Watch 的 Sprite Kit 中没有视图。 这就是为什么您无法在代码中使用视图的原因。

只需使用 SKSpriteNode 代替,如果您想要其他的纹理,请执行类似的操作。

例如这里我想在圆 2 上使用我的 circleOriginal 纹理

  let circleOriginal = SKSpriteNode(imageNamed: "circle")
  let circleTexture = circleOriginal.texture

  let circle2 = SKSpriteNode(texture: circleTexture)

如果您想对 Apple Watch 游戏技术有一个惊人的了解,请查看 Apple 的 WWDC 讲座(下面的幻灯片来自那里)。这解释了很多,并提供了很好的代码示例。

https://developer.apple.com/videos/play/wwdc2016/612/

以下是主要区别。

这是 Apple 针对非 watchOS 的场景图

这是 Apple 的 Scene Graph 对应 watchOS 的 Scene Graph

以下是 watchOS 的 SpriteKit / SceneKit 的推荐替代方案

【讨论】:

  • 谢谢@corey-f 的回答!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-17
  • 1970-01-01
  • 1970-01-01
  • 2017-11-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多