首页 > 解决方案 > SKSpriteNode.centerRect 不适用于 SKTextureAtlas

问题描述

我正在使用以下代码将 SKSpriteNode 添加到我的场景对象中。

  let atlas = SKTextureAtlas(named: "Ubiquity")
  let node = SKSpriteNode(texture: atlas.textureNamed("roundedBorder"))
  node.zPosition = 2000
  node.centerRect = CGRect(x: 0.4, y: 0, width: 0.2, height: 1)
  addChild(node)

毕竟,我的纹理看起来是扭曲的(请参阅附加的图像错误的图像)但是,如果我删除node.centerRect设置或将我的图像直接以下面的方式放入 xcasset

  let node = SKSpriteNode(texture: SKTexture(imageNamed: "ubiquity-roundedBorder"))
  node.zPosition = 2000
  node.centerRect = CGRect(x: 0.4, y: 0, width: 0.2, height: 1)
  addChild(node)

一切都按预期工作(请参阅附加的另一个图像正确的图像

标签: iossprite-kit

解决方案


我看到了同样的行为。这看起来像一个错误。


推荐阅读