SpriteKit - How to fix distortion in Node's an

2020-05-05 17:31发布

问题:

I have created an animation of various PNGs, but there are various frames that stretch to the border so the node is 'filled'. The animation should look like the GIF that I have created using the same pictures. Does anybody know how to make the animation look like the GIF?

GIF: Gif: Animation should look like this

Actual: Extra slow Actual result of the code

Border: Here you can see the border of the physics body that has the same size of the "node's border"

I have tried to fix the problem by switching the scene.scalemode. Further, I have tried to make the size of the Node dependent on the size of the textures. Neither looked like the GIF.

class GameScene: SKScene {

var player = SKSpriteNode()
var frames : Array = [SKTexture]()

override func didMove(to view: SKView) {

    //Color: Placeholder; Size should be size of original frames
    player = SKSpriteNode(color: .red, size: CGSize(width: 500,     height: 1000))

    //Physics
    player.physicsBody = SKPhysicsBody(rectangleOf: player.size)
    player.physicsBody?.affectedByGravity = false

    //Init the frames to the array
    for i in 1...6 {
        frames.append(SKTexture(imageNamed: "playerRunLeft-\(i)"))
    }
//        Tried to make the player size dependent on the image size - didn't work out
//        for i in frames {
//            player.size = i.size()
//        }

    //Attach the action
    let runAction = SKAction.animate(with: frames, timePerFrame: 0.3)
    player.run(SKAction.repeatForever(runAction))

    //Add to scene
    addChild(player)
    }
}