无法指定“Array <sktexture>”类型的值来键入“SKTexture”

时间:2017-01-21 21:20:45

标签: swift xcode sprite-kit

我在类中定义了一个SKTextures数组:

 def matrixMul(A, B):
        TB = zip(*B)
        return [[sum(ea*eb for ea,eb in zip(a,b)) for b in TB] for a in A]

    def pivotize(m):
        #Creates the pivoting matrix for m.
        n = len(m)
        ID = [[float(i == j) for i in range(n)] for j in range(n)]
        for j in range(n):
            row = max(range(j, n), key=lambda i: abs(m[i][j]))
            if j != row:
                ID[j], ID[row] = ID[row], ID[j]
        return ID

    def lu(A):
        #Decomposes a nxn matrix A by PA=LU and returns L, U and P.
        n = len(A)
        L = [[0.0] * n for i in range(n)]
        U = [[0.0] * n for i in range(n)]
        P = pivotize(A)
        A2 = matrixMul(P, A)
        for j in range(n):
            L[j][j] = 1.0
            for i in range(j+1):
                s1 = sum(U[k][j] * L[i][k] for k in range(i))
                U[i][j] = A2[i][j] - s1
            for i in range(j, n):
                s2 = sum(U[k][j] * L[i][k] for k in range(j))
                L[i][j] = (A2[i][j] - s2) / U[j][j]
        return (L)

    A = np.array([[1,1,3],[5,3,1],[2,3,1]])
    b = np.array([2,3,-1])
    print('LU factorization: ', lu(A))

    A = np.array([[1,1,3],[5,3,1],[2,3,1]])
    b = np.array([2,3,-1])
    print('Internal solver : ', np.linalg.solve(A,b))

然后我在同一个类中有一个函数返回该数组的元素:

var walking: Array<SKTexture> = []

我在代码的另一部分使用该函数,以便为我的角色设置动画:

func running() -> SKTexture{
    self.counter_run += self.counter_run
    if (self.counter_run >= 2){
        self.counter_run = 0
    }
    return self.walking[counter_run]
}

但是我收到了这个错误:

override func update(_ currentTime: TimeInterval) {
    player.texture = koopa.walking()
}

1 个答案:

答案 0 :(得分:2)

您正尝试将数组function Entry(props) { return ( <div> <h3>{props.name}</h3> </div> ); } class App extends Component { RenderEntry(id) { const data = request(id); console.log(request(id)); // undefined console.log(data); // undefined return <Entry name={data.name}/> } render() { return ( this.RenderEntry(8000) ); } } function request(id) { const base = 'https://url.com/' const request = new XMLHttpRequest(); request.open('GET', base + id, true); request.onload = function() { if (this.status >= 200 && this.status < 400) { // Success! const data = JSON.parse(this.response); // console.log(data); return data; } else { console.log('We reached our target server, but it returned an error!'); } }; request.onerror = function() { console.log('There was a connection error of some sort'); }; request.send(); } 分配给节点纹理,类型为walking

根据您要实现的目标,为节点设置一个SKTexture纹理:

walking

或使用动作:

player.texture = walking[counter_run]

编辑: 您的方法的纹理动画取决于您可能不想要的帧速率。因此我建议使用后者。