SpriteKit - How to fix distortion in Node's animation?

不打扰是莪最后的温柔 提交于 2019-12-20 05:47:24

问题


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)
    }
}

来源:https://stackoverflow.com/questions/54466927/spritekit-how-to-fix-distortion-in-nodes-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!