[英]How to use a sprite sheet in swift and sprite kit?
標題說明了一切。 如何在swift和sprite工具包中使用精靈表? 我搜索了谷歌,堆棧交換和蘋果文檔,我無法想出這個。
在xcode 7中,您可以使用Images.xcassets創建精靈地圖集。
如果使用正確的后綴(@ 2x和@ 3x)拖動所有三種圖像尺寸,它將自動為您填充圖像。
然后在代碼中使用這些資產只需寫:
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)
如果您正在使用已經創建的精靈表,請在SO上查看此答案: 在xcode中使用精靈表 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.