0
同時編程SKAction.animateWithTextures(...)我遇到了這個錯誤('String'is不能轉換爲'DictionaryIndex')當我使用我的「狀態」的字符串鍵來檢索SKTexture相關。有人可以解釋什麼可能是錯誤的原因?SpriteKit:'String'不能轉換爲'DictionaryIndex <String,SKTexture>'
import SpriteKit
class Player {
let states: Dictionary<String, SKTexture> = [
"standing": SKTexture(imageNamed: "standing"),
"right1": SKTexture(imageNamed: "right1"),
"right2": SKTexture(imageNamed: "right2"),
"right3": SKTexture(imageNamed: "right3"),
"left1": SKTexture(imageNamed: "left1"),
"left2": SKTexture(imageNamed: "left2"),
"left3": SKTexture(imageNamed: "left3")
]
let LEFT: UInt32 = 1 << 0
let FRONT: UInt32 = 1 << 1
let RIGHT: UInt32 = 1 << 2
var node: SKSpriteNode!
var status: UInt32!
let delay = SKAction.waitForDuration(NSTimeInterval(0.1))
var runLeft: SKAction!
var runRight: SKAction!
init(){
for state in states {
state.1.filteringMode = .Nearest
}
node = SKSpriteNode(texture: states["standing"])
node.physicsBody = SKPhysicsBody(rectangleOfSize: node.size)
node.physicsBody.dynamic = false
status = FRONT
runLeft = SKAction.animateWithTextures([states["left1"], states["left2"], states["left1"], states["left3"]]!, timePerFrame: 0.1)
runRight = SKAction.animateWithTextures([states["right1"], states["right2"], states["right1"], states["right3"]]!, timePerFrame: 0.1)
}
}
工作,謝謝! – Milese3 2014-09-03 17:29:42