TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Sprite Player Keeps Tipping Over

Forums > Swift

My player keeps tipping over when he comes into the scene, how do I stop this from happening?

// Player

    func createPlayer() {
        let playerTexture = SKTexture(imageNamed: "player-1")
        player = SKSpriteNode(texture: playerTexture)
        player.zPosition = 10
        player.position = CGPoint(x: frame.width / 6, y: frame.height * 0.75)
        player.physicsBody?.allowsRotation = false

        addChild(player)

        // Sets up pixel-perfect physics on the player
        player.physicsBody = SKPhysicsBody(texture: playerTexture, size: playerTexture.size())

        // Makes SpriteKit tell you any time the player collides with something
        player.physicsBody!.contactTestBitMask = player.physicsBody!.collisionBitMask

        // Makes the player respond to physics
        player.physicsBody?.isDynamic = true

        //player.physicsBody?.collisionBitMask = 0

        let frame2 = SKTexture(imageNamed: "player-2")
        let frame3 = SKTexture(imageNamed: "player-3")
        let frame4 = SKTexture(imageNamed: "player-4")
        let frame5 = SKTexture(imageNamed: "player-5")
        let frame6 = SKTexture(imageNamed: "player-6")
        let frame7 = SKTexture(imageNamed: "player-7")
        let frame8 = SKTexture(imageNamed: "player-8")
        let frame9 = SKTexture(imageNamed: "player-9")
        let frame10 = SKTexture(imageNamed: "player-10")
        //let frame11 = SKTexture(imageNamed: "player-11")
        //let frame12 = SKTexture(imageNamed: "player-12")

        let animation = SKAction.animate(with: [playerTexture, frame2, frame3, frame4, frame5, frame6, frame7, frame8, frame9, frame10,], timePerFrame: 0.1)
        let runForever = SKAction.repeatForever(animation)

        player.run(runForever)
        }

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.