ios - 如何在 swift 和 sprite 工具包中使用 sprite 表?

标签 ios macos swift sprite-kit sprite-sheet

标题说明了一切。我如何在 swift 和 sprite kit 中使用 sprite 表?我搜索了谷歌、堆栈交换和苹果文档,但我无法弄清楚这一点。

最佳答案

在 xcode 7 中,您可以使用 Images.xcassets 创建 Sprite 图集。

  1. 点击 Images.xcassets
  2. 点击左下角的加号
  3. 选择“新 Sprite 图集”
  4. 然后您可以将所有图像拖放到图集中

如果您使用适当的后缀(@2x 和@3x)拖入所有三种图像尺寸,它会自动为您填充图像。

然后要在代码中使用这些 Assets ,只需编写:

let atlas = SKTextureAtlas(named: "Sprites")
let texture = atlas.textureNamed("ball")
let sprite = SKSpriteNode(texture: texture)

你可以不那么具体,只指定一个纹理:

let texture = SKTexture(imageNamed: "ball")
let sprite = SKSpriteNode(texture: texture)

如果您希望使用已经创建的 Sprite 表,请在 SO 上查看此答案:Using sprite sheets in xcode .

关于ios - 如何在 swift 和 sprite 工具包中使用 sprite 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32635211/

相关文章:

javascript - Safari 推送通知 + 权限 "denied"且未找到日志

ios - 加载时不显示 UITableViewCell.detailTextLabel

xcode - 我如何在 Xcode 中订阅 TextField 的 TextChanged 事件

iOS 如何为每个目标创建配置文件

iphone - 使用 Core Graphics 绘图

ios - 获取错误 : Missing com. apple.developer.healthkit 权利

git fetch --tags --progress 在 Jenkins 中超时,在命令行上工作正常

iphone - 在运行时循环遍历所有对象属性

ios - 在 UITabController 中使用 UIScrollview 来显示不显示所有页面的 UIImageView

git - Macintosh Git SSH key 设置