这是让我走的问题之一"我怎么做?"
这是我得到的编译错误:
Use of instance member 'getAttackUPSequence_Frames' on type 'SKFootmanSprite' did you mean to use a value of type 'SKFootmanSprite' instead?
我为所有_Frames变量获取此信息。 以下是SKFootmanSprite的公共属性:
// ATTACK
static let attackUp_Frames = getAttackUPSequence_Frames()
static let attackDown_Frames: [SKTexture] = getAttackDOWNSequence_Frames()
static let attackLeft_Frames: [SKTexture] = getAttackLEFTSequence_Frames()
static let attackRight_Frames: [SKTexture] = getAttackRIGHTSequence_Frames()
static let attackUpRight_Frames: [SKTexture] = getAttackUPRIGHTSequence_Frames()
static let attackUpLeft_Frames: [SKTexture] = getAttackUPLEFTSequence_Frames()
static let attackDownLeft_Frames: [SKTexture] = getAttackDOWNLEFTSequence_Frames()
static let attackDownRight_Frames: [SKTexture] = getAttackDOWNRIGHTSequence_Frames()
这是获得攻击序列的功能之一:
func getAttackUPSequence_Frames() -> [SKTexture] {
var textures = [SKTexture]()
for var i = 1; i < 7; i+=1 {
let imageName = "footman_attack_up0" + String(i)
textures.append(SKTexture(imageNamed: imageName))
}
let imageName = "footman_up_stand"
textures.append(SKTexture(imageNamed: imageName))
return textures
}
我希望我的精灵帧能够使用let
代替var
。
(来自苹果的官方Swift教科书非常重视使用let
代替var
这样的事情。)
答案 0 :(得分:0)
您的问题是您的let
变量是静态的,但您的功能不是。
您应该尝试将您的函数getAttackUPSequence
设为静态。
该错误意味着您正试图从实例的“外部”访问实例成员(函数)。
答案 1 :(得分:0)
是的,你的函数getAttackUPSequence应该是静态的。