线程1:致命错误:索引超出范围spritekit

时间:2019-05-14 23:15:22

标签: ios arrays swift sprite-kit game-development

我正在游戏中制作动画。但是,我不断得到:

  

线程1:致命错误:索引超出范围

上:

mIndex.advanced(by: Double(Splits[state.hashValue]))

代码:

  enum States:Int {
        case idle = 0
        case running = 1
        case stopping = 2
        case jumping = 3
        case falling = 4
        case holding = 5
     }

var state: States
var Splits: [Int]
var mIndex = Double()

func animate() {
    if self.body != nil {
        if(state == .running) {
            mIndex = max(mIndex, Double(Splits[1]))
            mIndex += 0.2

            if (mIndex >= Double(Splits[2])) {
                mIndex = Double(Splits[1])
            }
        } else {
            mIndex.advanced(by: Double(Splits[state.hashValue]))                
            //Thread 1: Fatal error: Index out of range
            // mIndex = Double(Splits[state.hashValue]) //also tried but still same error 
        }
    }

起初我做到了:

mIndex = Double(Splits[state.hashValue])

但我仍然得到:

  

线程1致命错误索引超出范围

然后,我研究了该错误,并建议使用advanced(by:)。但是,它没有帮助。

我也做了:

mIndex.advanced(by: Double(Splits[state.rawValue]))

0 个答案:

没有答案