根据速度更改快速的SKSprite节点动画

“ SKSpriteNode”类型的值没有成员“ velocity”

我想根据我的SKSprite节点的速度更改动画,但是出现上面显示的错误,我不确定为什么

覆盖函数func touchesBegan(_ touches:设置,事件:UIEvent?){ super.touchesBegan(touches,with:event)

    if let location = touches.first?.location(in: self) {
    let horizontalaction = SKaction.move(to: location,duration: 1.0)
        horizontalaction.timingMode = SKactionTimingMode.easeOut
      player?.run(horizontalaction)

        let playerAnimatedAtlas = SKTextureAtlas(named: "animation")
             var walkFrames: [SKTexture] = []
               var lwalkFrames: [SKTexture] = []


             let numImages = playerAnimatedAtlas.textureNames.count
             for i in 1...numImages {
               let playerTextureName = "player\(i)"
               let playerLeftTextureName = "lplayer\(i)"
               walkFrames.append(playerAnimatedAtlas.textureNamed(playerTextureName))
               lwalkFrames.append(playerAnimatedAtlas.textureNamed(playerLeftTextureName))
             }
             walkingPlayer = walkFrames
             lwalkingPlayer = lwalkFrames

               let leftFrameTexture = lwalkingPlayer[0]
               let firstFrameTexture = walkingPlayer[0]

        player!.physicsBody?.isDynamic = true

        player!.physicsBody = SKPhysicsBody(texture: firstFrameTexture,size: player!.texture!.size())

        if player!.velocity.dx < 0 {
 //ERROR: Value of type 'SKSpriteNode' has no member 'velocity' ****
            player! = SKSpriteNode(texture: leftFrameTexture)
        }

        else if player!.velocity.dx > 0 {
//ERROR: Value of type 'SKSpriteNode' has no member 'velocity' ****
            player! = SKSpriteNode(texture: firstFrameTexture)
        }

    }
}
iCMS 回答:根据速度更改快速的SKSprite节点动画

尝试player!.physicsBody.velocity

(我知道这不是您的问题,但最终请尽量不要在各处都使用!-使用if letguard let

本文链接:https://www.f2er.com/2187748.html

大家都在问