我正在製作一個簡單的動畫,熊來回移動。我的問題是,我的代碼無法識別我的atlas文件夾(BearImages.atlas)或不能識別圖像。我不知道我做錯了什麼,我也搞不懂。你可以向我解釋,因爲我5歲,爲什麼xCode不能識別我的文件夾或我的圖像?Swift Sprite動畫:xCode不會讀取我的atlas文件夾
截圖:
我的代碼:
import SpriteKit
class GameScene: SKScene {
var bear : SKSpriteNode!
var bearWalkingFrames : [SKTexture]!
override func didMoveToView(view: SKView) {
backgroundColor = (UIColor.blackColor())
let bearAnimatedAtlas = SKTextureAtlas(named: "BearImages")
var walkFrames = [SKTexture]()
print(bearAnimatedAtlas)
let numImages = bearAnimatedAtlas.textureNames.count
for var i=1; i<=numImages/2; i++ {
let bearTextureName = "bear\(i)"
walkFrames.append(bearAnimatedAtlas.textureNamed(bearTextureName))
}
bearWalkingFrames = walkFrames
let firstFrame = bearWalkingFrames[0]
bear = SKSpriteNode(texture: firstFrame)
bear.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
addChild(bear)
walkingBear()
}
func walkingBear() {
//This is our general runAction method to make our bear walk.
bear.runAction(SKAction.repeatActionForever(
SKAction.animateWithTextures(bearWalkingFrames,
timePerFrame: 0.1,
resize: false,
restore: true)),
withKey:"walkingInPlaceBear")
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
}
override func update(currentTime: CFTimeInterval) {
}
}
謝謝!
你是如何創建這個地圖集的? – Knight0fDragon